๐ŸHow to explain itโ‰๏ธ๐Ÿค”๐Ÿคฃ๐Ÿ™ƒ๐Ÿค• & more... | Sololearn: Learn to code for FREE!
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

4th Dec 2019, 1:16 PM
Janusz Bujak ๐Ÿ‡ต๐Ÿ‡ฑ ๐Ÿ‡บ๐Ÿ‡ฆ
Janusz Bujak ๐Ÿ‡ต๐Ÿ‡ฑ ๐Ÿ‡บ๐Ÿ‡ฆ - avatar
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.
4th Dec 2019, 5:12 PM
HonFu
HonFu - avatar
+ 12
HonFu Thanks for explanationsโ€ผ๏ธโ˜บ๏ธ It all schows that ๐Ÿ is dangerous & can bit youโ‰๏ธ๐Ÿค”๐Ÿ™ƒ
4th Dec 2019, 8:42 PM
Janusz Bujak ๐Ÿ‡ต๐Ÿ‡ฑ ๐Ÿ‡บ๐Ÿ‡ฆ
Janusz Bujak ๐Ÿ‡ต๐Ÿ‡ฑ ๐Ÿ‡บ๐Ÿ‡ฆ - avatar