0

Can someone clarify the logic behind these assignment statements.

>>> True
True
>>> True = False
>>> True
False
>>> True = True
>>> True
False
>>> a = True
>>> if a:
...     print "a is True"
... else:
...     print "a is False"
...
a is False

According to the manual, the only two instances of class bool is True and False.

Help on bool object:

True = class bool(int)
 |  bool(x) -> bool
 |
 |  Returns True when the argument x is true, False otherwise.
 |  The builtins True and False are the only two instances of the class bool.
 |  The class bool is a subclass of the class int, and cannot be subclassed.
 |
 |  Method resolution order:
 |      bool
 |      int
 |      object

So am I overriding the default instance? And if so, why does python does not assign True to is default instance in the below assignment? How can I assign the default python True in the below statement?

>>> True = False
>>> True
False
>>> True = True
>>> True
False     #why?

Thanks in advance for any help!!!

TerminalWitchcraft
  • 1,732
  • 1
  • 13
  • 18

1 Answers1

0

When you do:

True = False

True becomes False.. And when you do:

True = True

It's like writing:

True = False

If you want to make it the "original" True again, you should:

>>> True = not True # recall that you assigned False to True
>>> True
True
Maroun
  • 94,125
  • 30
  • 188
  • 241