Sign in or Join FriendFeed
FriendFeed is the easiest way to share online. Learn more »
aydın
a is not b but p is q, guess why
isequal.png
i think you found a bug? - Joan Miro
@mirat, i m not sure, basically "is" is not for equivalent, it is for object identification but the strange thing is why it differs - aydın
yeap the point is python caches small ints (till 256) and when you define an int it returns cached small int object so "is" comparasion passes but after 256 python creates new object and "is" failed, thanks to ahmet :) - aydın
Extra credit, explain: p=1000; q=1000; p is q - Rob Syme
Every code object has a tuple of constants. The LOAD_CONST opcode loads a constant from this tuple onto the VM stack. So every time 1000 occurs in the program text, it refers to the same object in the tuple of constants for that block. At an interactive interpreter, each line is its own block. You can put multiple simple statements in one statement with semi-colons, so here you've forced p and q to be compiled into the same code object. If you typed three separate statements, p is q would be False. (If you put the assignment statements inside a function, they'd also share the same constants.) - Jeremy Hylton
it is clearer for now, thanks jeremy - aydın
interesting - BeKiR
thanks for this feed - amir
thanks to all - Joan Miro