Re:Strong Types and Their Impact on Testing
by ForHackernews on Wednesday November 19, 2014 @08:55PM
(#8633974)
> True being coercible to a number is unfortunate
If we want to be really pedantic, in Python 2.X, True isn't coercible to an integer, it is an integer.
>>> True == 1
True
>>> isinstance(True, int)
True
This is an artifact of the fact that when Python was first created, it didn't have boolean types, so when they were added later, "True" and "False" were bolted on as aliases to the integers 1 and 0.
If we want to be really pedantic, in Python 2.X, True isn't coercible to an integer, it is an integer.
>>> True == 1 True >>> isinstance(True, int) True
This is an artifact of the fact that when Python was first created, it didn't have boolean types, so when they were added later, "True" and "False" were bolted on as aliases to the integers 1 and 0.