New course! Every coder should learn Generative AI!
Try a free lesson+ 20
๐How to explain itโ๏ธ๐ค๐คฃ๐๐ค & more...
# SL PlayGound a = 300 b = 300 print(a is b) # True a, b = 300, 300 print(a is b) # False # True in Pycharm Python 3.8.0 Shell >>> a = 300 >>> b = 300 >>> a is b False >>> a, b = 300, 300 >>> a is b True >>> https://code.sololearn.com/che8Hyz22KLz/?ref=app
2 Answers
+ 6
The specification of Python says that with immutable numbers - like int - Python may secretly only store one value for all the occurrences of that string, but doesn't have to.
In some cases you'll encounter two separate (equal) numbers, in other cases they may be only one number in memory. It doesn't matter and you don't have to give a heck.
Only for mutable objects Python *has to* enforce separate objects, because you need to know (for example) which list you are filling with stuff right now.
+ 12
HonFu Thanks for explanationsโผ๏ธโบ๏ธ
It all schows that ๐ is dangerous & can bit youโ๏ธ๐ค๐