Python can be weird. Let’s explore some strange examples.
Example 1 - 8 bit issue?
>>> a = 256 >>> b = 256 >>> a is b True >>> a = 257 >>> b = 257 >>> a is b False
Example 2 - Where did Ruby go?
>>> programming = dict() >>> programming[5.5] = "JavaScript" >>> programming[5.0] = "Ruby" >>> programming[5] = "Python" >>> programming[5.5] 'JavaScript' >>> programming[5] 'Python' >>> programming[5.0] 'Python'
Example 3 - not valid?
>>> x = True >>> y = False >>> not x == y True >>> y == not x File "<stdin>", line 1 y == not x ^ SyntaxError: invalid syntax
Example 4 - huh!?
>>> a = "wtf" >>> b = "wtf" >>> a is b True >>> a = "wtf!" >>> b = "wtf!" >>> a is b False