+ 2
[SOLVED] Difference between 'is' and '==' in python
According to geeksforgeeks the difference between 'is' and '==' in Python is that 'is' checks whether both operands refer to the same object or not whereas '==' checks whether both operands are equal or not. In the below mentioned code why does 'is' doesn't show 40585 whereas '==' shows. https://code.sololearn.com/ctziQc5akrQF/?ref=app
2 odpowiedzi
+ 3
1. Do not use "is" to compare integers. You may not get the results you expect.
2. Python caches small integers for efficiency. Every time you create a reference to a small integer, you are referring to the cached number, not a new object.
https://stackoverflow.com/questions/306313/
0
Thanks guys!!👍