Here was my problem: I needed to reverse a boolean value throughout a loop. True, False, True, False, etc. In most languages, let's say PHP, that looks like this:
$var = !$var;
Python doesn't like the ! when used in this context. However, I got to thinking, and this is what I came up with.
var = var == False
or
var = var != True
Hope this is useful to someone.




December 16th, 2007 at 4:39 am
>>> var = True
>>> var = not var
>>> var
False
December 16th, 2007 at 7:22 pm
Oh, cool, I hadn't thought of that. Neat.