stillanoob
stillanoob

Reputation: 1379

Reset built-in constants

While running a Python 2.7 interpreter, I assigned False to True. Is there a way to reset True to its original value without restarting the interpreter? (Assume there isn't any user defined explicit reference available to the original True in the interpreter environment.)

Upvotes: 1

Views: 49

Answers (2)

blhsing
blhsing

Reputation: 106588

You can get it from the __builtin__ module:

import __builtin__
True = __builtin__.True

so that:

import __builtin__
True = False
print(True)
True = __builtin__.True
print(True)

would output:

False
True

Upvotes: 1

Ray Toal
Ray Toal

Reputation: 88378

Yes.

True = (1 == 1)

Note:

>>> True = False
>>> True
False
>>> True and True
False
>>> True = (1 == 1)
>>> True
True
>>> True and True
True

Upvotes: 3

Related Questions