Reputation: 61355
I can't understand what is happening here?
True = False
False = True
print True, False
False False
Isn't the output be printed as False True
?
Upvotes: 0
Views: 105
Reputation: 32189
Once you do True = False
, True
is no longer a boolean but rather a variable that has been assigned the boolean False
. Therefore, the line False = True
is actually assigning True
's value (False
) to the variable False
.
Upvotes: 1
Reputation: 123498
You seem to be using Python 2.
This wouldn't work in Python 3 as True
and False
were changed to keywords in order to make assignment to those impossible.
Refer to Core Language Changes:
Make
True
andFalse
keywords. [6]Reason: make assignment to them impossible.
Upvotes: 3
Reputation: 10650
You are setting True = False
, and then False = True
.
True = False
False = True # But "True" here is now False.
print True, False # True = False, because of the first line. As does False, because you set it equal to "True" which you have already made == False.
I don't know why you would ever want to do this, other than to mess with someone's code, as it's a readability nightmare - as you can see just from the difficulty in using the words to explain it.
If you really want to swap the vaules around, then do:
True, False = False, True
Upvotes: 8