In some part of my Python program I have a val variable that can be 1 or 0. If it\'s 1 I must change to 0, if it\'s 0 I must change to 1.
How do you do it in a Pytho
To expand upon the answer by "YOU", use:
int(not(val))
Examples:
>>> val = 0 >>> int(not(val)) 1 >>> val = 1 >>> int(not(val)) 0
Note that this answer is only meant to be descriptive, not prescriptive.