Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 [python] Something neat
Index -> General Discussion
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Raknarg




PostPosted: Wed Jan 15, 2014 3:43 pm   Post subject: [python] Something neat

This didn't seem to fit anywhere in the python section, but apparently this is valid:

True = False

Now True will equate to False.
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Wed Jan 15, 2014 4:09 pm   Post subject: RE:[python] Something neat

although
code:

>>> True = False
>>> print True
False
>>> print 1==1
True
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Raknarg




PostPosted: Wed Jan 15, 2014 6:26 pm   Post subject: RE:[python] Something neat

How strange. Any idea how this is?
Tony




PostPosted: Wed Jan 15, 2014 7:15 pm   Post subject: RE:[python] Something neat

there's a difference between "True" the variable and "True" the value. It kind of looks like there's a variable called True and it initially holds a value that has a string representation of "True".
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Raknarg




PostPosted: Wed Jan 15, 2014 7:16 pm   Post subject: RE:[python] Something neat

Right, I was thinking something along that, maybe it was a built in function that returns true
Dreadnought




PostPosted: Wed Jan 15, 2014 7:34 pm   Post subject: Re: [python] Something neat

Raknarg wrote:

Right, I was thinking something along that, maybe it was a built in function that returns true

Not a function, its an object of type bool.The object has a value of True in expressions but as Tony says it has a string representation (what you see when you print it) of 'True'.
You can see this
Python:
>>> int(True)
1
>>> type(True)
<type 'bool'>
>>> type(True.__repr__())
<type 'str'>
>>> True.__repr__()
'True'


EDIT: Interesting note, True = False is illegal in python 3 (at least in my version). It seems that they are now keywords.
Raknarg




PostPosted: Wed Jan 15, 2014 7:43 pm   Post subject: RE:[python] Something neat

Ah. Thanks for that.
Display posts from previous:   
   Index -> General Discussion
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 7 Posts ]
Jump to:   


Style:  
Search: