import dis def testMethod1(): a, b = 300, 300 print dis.dis(testMethod1)
Print
4 0 LOAD_CONST 2 ((300, 300))
3 UNPACK_SEQUENCE 2
6 STORE_FAST 0 (a)
9 STORE_FAST 1 (b)
12 LOAD_CONST 0 (no)
15 RETURN_VALUE No
def testMethod2(): a = 300 b = 300
Print
7 0 LOAD_CONST 1 (300)
3 STORE_FAST 0 (a)
8 6 LOAD_CONST 1 (300)
9 STORE_FAST 1 (b)
12 LOAD_CONST 0 (no)
15 RETURN_VALUE No
So, it looks essentially the same, but with LOAD_CONST in one step in the first method and two steps in the second method ....
EDIT
After some testing, I found that both methods return False in the end; however, with one run, i.e. without putting the methods in a loop, they seem to always return True . Sometimes it uses one link, and sometimes not.
The documentation only states that from -5 to 256 will return the same link; therefore, you simply should not use is for comparison (in this case), since the current id number has no guarantee.
NB: you never want to use is to compare values, as that is not what it is necessary for to compare identifiers. My point was that the return value of is will not always be True when you are outside the given range.
Steve P.
source share