0

difference between is and == in python3.why the same is operator giving different output when comparing id of the list and direc

ex:>>> dates=[1,2,3,4,5,] >>> number=dates >>> id(dates) is id(number) False >>> id(dates) 18091624 >>> id(number) 18091624 >>> id(dates)==id(number) True >>> m=[1,2,3] >>> dates is number True >>>

20th Dec 2018, 6:13 PM
Vijaya Karanki
Vijaya Karanki - avatar
2 Réponses
+ 4
is checks the object instances to see if they are the same. id(dates) is id(number) has two different integers both with the same value so false. dates is number both have the same list instance so true. == checks the values are the same.
20th Dec 2018, 6:50 PM
John Wells
John Wells - avatar
+ 1
thanks for quick response. now i understood
20th Dec 2018, 6:58 PM
Vijaya Karanki
Vijaya Karanki - avatar