True = False
Assigning to True
Page 1 of 14 Replies - 244 Views - Last Post: 01 January 2013 - 08:21 AM
#1
Assigning to True
Posted 29 December 2012 - 03:36 PM
Why is it possible to assign a value to the keywords True and False in Python? In particular the following code gives the keyword True the value False and suddenly I only have the value False to work with.
Replies To: Assigning to True
#2
Re: Assigning to True
Posted 29 December 2012 - 03:39 PM
I can't do this in Python 3. But the question arises.. why would you want to?
In Javascript I can do things like window = null, but I don't really want to!?
In Javascript I can do things like window = null, but I don't really want to!?
This post has been edited by andrewsw: 29 December 2012 - 03:42 PM
#3
Re: Assigning to True
Posted 29 December 2012 - 03:44 PM
This ran in Python 2.7.3. I completely agree that you would never want to do this, but I was showing someone some intro programming stuff and was shocked when she typed this in and Python allowed it.
#4
Re: Assigning to True
Posted 29 December 2012 - 03:44 PM
In Python 2 True and False aren't keywords, they're ordinary variables. So that's the reason you can reassign them (as for why you'd want to: I have no idea).
In Python 3 they're keywords and can not be assigned to.
In Python 3 they're keywords and can not be assigned to.
#5
Re: Assigning to True
Posted 01 January 2013 - 08:21 AM
>>> True = False >>> True False
>>> False = True >>> False True >>>
...wow.
This post has been edited by BloodyInari: 01 January 2013 - 08:27 AM
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote




|