4 Replies - 391 Views - Last Post: 01 January 2013 - 08:21 AM Rate Topic: -----

#1 ComputerAnalysis  Icon User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 92
  • Joined: 29-June 09

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.

True = False


Is This A Good Question/Topic? 0
  • +

Replies To: Assigning to True

#2 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3234
  • View blog
  • Posts: 10,860
  • Joined: 12-December 12

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!?

This post has been edited by andrewsw: 29 December 2012 - 03:42 PM

Was This Post Helpful? 0
  • +
  • -

#3 ComputerAnalysis  Icon User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 92
  • Joined: 29-June 09

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.
Was This Post Helpful? 0
  • +
  • -

#4 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2089
  • View blog
  • Posts: 3,181
  • Joined: 21-June 11

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.
Was This Post Helpful? 2
  • +
  • -

#5 BloodyInari  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 106
  • Joined: 16-November 09

Re: Assigning to True

Posted 01 January 2013 - 08:21 AM

>>> True = False
>>> True
False


>>> False = True
>>> False
True
>>> 



...wow. :o

This post has been edited by BloodyInari: 01 January 2013 - 08:27 AM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1