Apr-28-2024, 07:42 AM
hi
in the below code:
in shell if i write:
>>> x=257
>>> y=257
>>> id(x)==id(y)
False
but this is inconsistence with result of running line 22 of the above code.
can explain to me the reason of this?
thanks for any reply.
in the below code:
#from: https://realpython.com/python-assignment-operator/ ''' to detemine intering range for integers''' from platform import python_version interning = [ x for x, y in zip(range(-10, 500), range(-10, 500)) if x is y ] print( f"Interning interval for Python {python_version()} is:" f" [{interning[0]} to {interning[-1]}]" ) x=-4 y=-4 print(id(x)==id(y)) #True x=257 y=257 print(id(x)==id(y)) #in shell is false but in script run results true ? x=256 y=256 print(id(x)==id(y)) #Trueafter running( i use Thonny) is:
Output:Interning interval for Python 3.10.11 is: [-5 to 256]
True
True
True
my issue is about line 22.in shell if i write:
>>> x=257
>>> y=257
>>> id(x)==id(y)
False
but this is inconsistence with result of running line 22 of the above code.
can explain to me the reason of this?
thanks for any reply.