Inconsistency in outputs given by Python IDLE (using both Shell and Interactive modes) and Google Colabs

54 Views Asked by At

I tried a code regarding the IDs of dictionaries I created in Python, but the same code gives a different output when I run it on IDLE and when I run it on Google Colabs. Could anyone explain this?

What confuses me is the inconsistent output of this line:

print(f'ID1 == ID2: {id1 == id2}')

The code I used in IDLE was:

print('This is the output in a saved program:')
rec = {"Name": "Python", "Age": "20", "Addr": "NJ", "Country": "USA"}
id1 = id(rec)
print(f'ID1: {id1}')[![enter image description here][1]][1]
del rec
rec = {"Name": "Python", "Age": "20", "Addr": "NJ", "Country": "USA"}
id2 = id(rec) 
print(f'ID2: {id2}')
print(f'ID1 == ID2: {id1 == id2}')

The output I get is:

This is the output in a saved program:
ID1: 2005032928640
ID2: 2005032928640
ID1 == ID2: True

In Google Colab:

rec = {"Name": "Python", "Age": "20", "Addr": "NJ", "Country": "USA"}
id1 = id(rec)
print(f'ID1: {id1}')
del rec
rec = {"Name": "Python", "Age": "20", "Addr": "NJ", "Country": "USA"}
id2 = id(rec)
print(f'ID2: {id2}')
print(f'ID1 == ID2: {id1 == id2}')

Output:

ID1: 132233348202304
ID2: 132233833050560
ID1 == ID2: False
0

There are 0 best solutions below