why "is" operator works differently in python3 against python2 | Sololearn: Learn to code for FREE!


why "is" operator works differently in python3 against python2

x = 2*2 y = 8/2 x is y #returns true in python 2 x is y #returns false in python 3

10/26/2018 2:15:58 PM

Aamirsohel khan

2 Answers

New Answer


In both Python 2 and 3, "is" checks whether the identities of its two arguments are the same. The difference is in the "/" operator. In Python 2, "/" uses floor division if both its arguments are integers, and thus the result is always an integer. But in Python 3, "/" is true division, and result is always a float. So y=8/2=4 is an integer in Python 2, but in Python 3, it's the float 4.0. But x is 4 in both versions. So in Python 2, "x is y" means "4 is 4" (True). But in Python 3, it means "4 is 4.0" (False).


In python3 there are some big changes.so don't worry about this what's going on in python2.focus only on python3. i think in python2 if two variable has same magnitude or value then they point same object that's why it give you true but in python3 although two variable has same value but they always point diffrent objects not same why you got false in python3.