How do I undo True = False in python interactive mode?
This video explains
How do I undo True = False in python interactive mode?
--
Become part of the top 3% of the developers by applying to Toptal
https://topt.al/25cXVn
--
Music by Eric Matyas
https://www.soundimage.org
Track title: Puzzle Meditation
--
Chapters
00:00 Question
00:41 Accepted answer (Score 137)
00:56 Answer 2 (Score 47)
01:34 Answer 3 (Score 37)
01:47 Answer 4 (Score 17)
02:12 Thank you
--
Full question
https://stackoverflow.com/questions/3056...
Question links:
[here]: https://stackoverflow.com/questions/1276...
Accepted answer links:
[del]: https://docs.python.org/2/reference/simp...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #boolean #python2.x
#avk47
How do I undo True = False in python interactive mode?
--
Become part of the top 3% of the developers by applying to Toptal
https://topt.al/25cXVn
--
Music by Eric Matyas
https://www.soundimage.org
Track title: Puzzle Meditation
--
Chapters
00:00 Question
00:41 Accepted answer (Score 137)
00:56 Answer 2 (Score 47)
01:34 Answer 3 (Score 37)
01:47 Answer 4 (Score 17)
02:12 Thank you
--
Full question
https://stackoverflow.com/questions/3056...
Question links:
[here]: https://stackoverflow.com/questions/1276...
Accepted answer links:
[del]: https://docs.python.org/2/reference/simp...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #boolean #python2.x
#avk47
ACCEPTED ANSWER
Score 137
You can simply del your custom name to set it back to the default:
>>> True = False
>>> True
False
>>> del True
>>> True
True
>>>
ANSWER 2
Score 47
This works:
>>> True = False
>>> True
False
>>> True = not False
>>> True
True
but fails if False has been fiddled with as well. Therefore this is better:
>>> True = not None
as None cannot be reassigned.
These also evaluate to True regardless of whether True has been reassigned to False, 5, 'foo', None, etc:
>>> True = True == True # fails if True = float('nan')
>>> True = True is True
>>> True = not True or not not True
>>> True = not not True if True else not True
>>> True = not 0
ANSWER 3
Score 17
For completeness: Kevin mentions that you could also fetch the real True from __builtins__:
>>> True = False
>>> True
False
>>> True = __builtins__.True
>>> True
True
But that True can also be overriden:
>>> __builtins__.True = False
>>> __builtins__.True
False
So better to go with one of the other options.
ANSWER 4
Score 11
Just do this:
True = bool(1)
Or, because booleans are essentially integers:
True = 1