Possible Duplicate:
Why can’t Python handle true/false values as I expect?
Seems a stupid question, but why is the following statement in Python not explicitly forbidden?
>> True=False
>> True
False
How is True
and False
handled by Python interpreter?
2 is True is false (as is 1 is True ). Sure, bool() will return True for non-zero integer inputs, but that doesn't mean the values "are" True .
The Python Boolean type is one of Python's built-in data types. It's used to represent the truth value of an expression. For example, the expression 1 <= 2 is True , while the expression 0 == 1 is False . Understanding how Python Boolean values behave is important to programming well in Python.
Python interprets multiple (in)equalities the way you would expect in Math: In Math a = b = c mean all a = b , b = c and a = c . So True is False == False means True == False and False == False and True == False , which is False .
Hence, % in %hist does not exist in all python interpreters. Thus the statement is false.
True
, just like str
or any other builtin, is just a name that exists in the scope by default. You can rebind it like any other such name.
Python actually has very few reserved words. All the rest are subject to redefinition. It's up to you to be careful!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With