https://stackoverflow.com/questions/13650293/understanding-pythons-is-operator
“The operators is and is not test for object identity: x is y is true if and only if x and y are the same object. x is not y yields the inverse truth value. [6]”
https://docs.python.org/2/reference/expressions.html#is
This next part explained a lot for me in the way of your question
is and is not are the two identity operators in Python. is operator does not compare the values of the variables, but compares the identities of the variables. Consider this:
>>> a = [1,2,3]
>>> b = [1,2,3]
>>> hex(id(a))
'0x1079b1440'
>>> hex(id(b))
'0x107960878'
>>> a is b
False
>>> a == b
True
>>>
The above example shows you that the identity (can also be the memory address in Cpython) is different for both a and b (even though their values are the same). That is why when you say a is b it returns false due to the mismatch in the identities of both the operands. However when you say a == b, it returns true because the == operation only verifies if both the operands have the same value assigned to them.
From the stack overflow link
If you can, I would look at the memory links when you run your tests and see what is actually being pointed to when you execute it.
In your example the compiler is probably looking at your initialization of the the “two” and “too” variables and figuring
"well crap this guy statically assigned the same value (==) to both of these variables, might as well point to the same memory space while inside this code module, but when compiled with an expression (such as a=b+2, (which would be interesting to see if it used the same “ID” for
a=1
b=a+0
c=a+b
d=2
z=a+b
id(a)
id(b)
id(c)
id(d)
id(z)
)) for the variable definition it doesn’t know what the value may be till it runs therefore it can’t link the variables to the same memory space".
This could have been done to save memory allocation due to lazy programmers who would use multiple statically assigned variables that all had the same value.
edits for formatting, hey looky here wrote my first little bit of python