+ 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

7th Oct 2019, 7:04 PM
Saurabh Tiwari
Saurabh Tiwari - avatar
4 Respuestas
+ 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/
7th Oct 2019, 7:30 PM
Diego
Diego - avatar
0
Thanks guys!!👍
7th Oct 2019, 7:39 PM
Saurabh Tiwari
Saurabh Tiwari - avatar