Course Name: Python for Trading: Basic, Section No: 2, Unit No: 6, Unit type: Notebook
This isn't necessarily true, so maybe it warrants a correction?
t1 = 123456789123456789
t2 = 123456789123456789
id(t1) == id(t2) -> False
Hi Kaan,
Whenever we run a program in Python, all the integers between -5 and 256 (both inclusive) are allocated a space in the memory. Whenever these values are assigned to a variable, the variable simply points to the already allocated values. Hence if you compare the address, you get a True. These allocated addresses remain unchanged unless you terminate the program.
For any value outside this range, the memory is allocated when the corresponding line is encountered. This will change every time you run the code. Since the value you mentioned above (123456789123456789) is outside the range, different memory is allocated for both t1 and t2. Thus when you compare the address, you get a false.
Hope this helps.
Thanks!