is there an easy way to toggle a boolean in python, like
?Code:bool1 = !bool1
Thanks in advance.
is there an easy way to toggle a boolean in python, like
?Code:bool1 = !bool1
Thanks in advance.
"The secret to creativity is knowing how to hide your sources." -Albert Einstein
Ubuntu User #32977; Linux User #528876
literally:Code:Python 2.6.5 |EPD 6.2-2 (32-bit)| (r265:79063, May 28 2010, 15:13:03) [GCC 4.0.1 (Apple Inc. build 5488)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> b = True >>> print not b False >>> b = not b >>> print b False
Code:bool = not bool
bool1 = not bool1
thanks for the fast responses! works like a charm!
"The secret to creativity is knowing how to hide your sources." -Albert Einstein
Ubuntu User #32977; Linux User #528876
Discovered this today, but am still posting it in case someone searching on the web will be looking for it.
Alternative solution to toggling the boolean:
example:Code:b ^= True
Code:Python 2.7 (r27:82500, Aug 07 2010, 16:54:59) [GCC] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> b = True >>> b ^= True; b False >>> b ^= True; b True >>> b ^= True; b False
Bookmarks