Apr-03-2017, 01:01 AM
(Apr-02-2017, 11:48 PM)micseydel Wrote:well, that is the problem.(Apr-01-2017, 08:25 PM)Nirelg Wrote: why "2**32 is 2**32" gives us output of "False"?Generally,is
should not be used to compare ints (or for equality in general) in Python. The fact that for small values it does work is a consequence of an optimization - since the lower numbers are used so much, Python caches them to avoid having duplicates. It doesn't bother for higher numbers.
If that doesn't quite make sense, the wonderful video Ofnuts provided has a lot of good background information. Batchelder is great in general as well.
It should not "bother" for higher numbers, but when i write the code:
print id(1000) print id(1000)They both have the same id even tho they are high numbers (even tried with higher numbers).
Output:41870080
41870080
I also wrote "print 1000 is 1000" giving me "True", so why it works the same with higher numbers even tho it shouldn't?keep in mind that when I write "2**10 is 2**10" it will write False! yet when doing it with the numbers them self (like 1000) it gives me True.
I watched the entire video, it helped me a lot to understand how python works, but it still did not solve the question why it gave me the same id when it should not have lol.