You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In Python 2 (tested 2.7.15+ on Debian), the boolean operators True and False are in fact not literals, and can be reassigned. Unfortunately, I can't remember where I found this, but I've used it a few times to mess with people's code. Good fun :)
>>>TrueTrue>>>FalseFalse>>>True==FalseFalse# as expected!>>>True=False# Note, only 1 '='. This is assignment!>>>TrueFalse# !!>>>True==False# normally, False. Now, we're expecting...True
The reverse is also possible:
>>>False=True# assignment, not equality check>>>ifFalse: print("Hello World!") # this should never work.
...
HelloWorld!
Unfortunately, this behavior was removed in Python 3 by setting True and False to be literals. I can't seem to find this alluded to in the list; let me know if it's worthy of a PR.
The text was updated successfully, but these errors were encountered:
@mishaturnbull Yes, it's definitely worth a PR. We already have a few WTFs that only work on specific versions of python, so there is no issue adding more as long as they're interesting.
In Python 2 (tested 2.7.15+ on Debian), the boolean operators
True
andFalse
are in fact not literals, and can be reassigned. Unfortunately, I can't remember where I found this, but I've used it a few times to mess with people's code. Good fun :)The reverse is also possible:
Unfortunately, this behavior was removed in Python 3 by settingTrue
andFalse
to be literals. I can't seem to find this alluded to in the list; let me know if it's worthy of a PR.The text was updated successfully, but these errors were encountered: