Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

True=False assignment in Python 2.x [duplicate]

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?

like image 965
linello Avatar asked Nov 15 '12 16:11

linello


People also ask

Is 2 considered true in Python?

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 .

How do you make a true/false in Python?

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.

What is false false 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 .

Does the in %hist exist in all Python interpreters?

Hence, % in %hist does not exist in all python interpreters. Thus the statement is false.


2 Answers

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.

like image 77
wRAR Avatar answered Sep 28 '22 08:09

wRAR


Python actually has very few reserved words. All the rest are subject to redefinition. It's up to you to be careful!

like image 24
Mark Ransom Avatar answered Sep 28 '22 07:09

Mark Ransom