Is there a better way to do a toggle in python, like a nyvalue = not myval ? Answer Use the not boolean operator: not returns a boolean value (True or False): If you must have an integer, cast it back: However, the python bool type is a subclass of int, so this may not be needed: