I am looking for a short syntax that would look somewhat like x *= -1
where x
is a number, but for booleans, if it even exists. It should behave like b = not(b)
. The interested of this is being able to flip a boolean in a single line when the variable name is very long.
For example, if you have a program where you can turn on|off lamps in a house, you want to avoid writing the full thing:
self.lamps_dict["kitchen"][1] = not self.lamps_dict["kitchen"][1]