
-----------------------------------
Raknarg
Wed Jan 15, 2014 3:43 pm

[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.

-----------------------------------
Tony
Wed Jan 15, 2014 4:09 pm

RE:[python] Something neat
-----------------------------------
although
[code]
>>> True = False
>>> print True
False
>>> print 1==1
True
[/code]

-----------------------------------
Raknarg
Wed Jan 15, 2014 6:26 pm

RE:[python] Something neat
-----------------------------------
How strange. Any idea how this is?

-----------------------------------
Tony
Wed Jan 15, 2014 7:15 pm

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".

-----------------------------------
Raknarg
Wed Jan 15, 2014 7:16 pm

RE:[python] Something neat
-----------------------------------
Right, I was thinking something along that, maybe it was a built in function that returns true

-----------------------------------
Dreadnought
Wed Jan 15, 2014 7:34 pm

Re: [python] Something neat
-----------------------------------

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
>>> int(True)
1
>>> type(True)

>>> type(True.__repr__())

>>> 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
Wed Jan 15, 2014 7:43 pm

RE:[python] Something neat
-----------------------------------
Ah. Thanks for that.
