+ 5

Why are the outputs not matching for same code on different compilers.

a=500 b=500 print(a is b) output by python 3.7 idle ( installed from python.org) is: False output by online ide of python 3.6 like codechef,geeksforgeeks is: True

6th Nov 2018, 9:53 PM
Vishal kumar
Vishal kumar - avatar
3 ответов
+ 8
A very good explanation: https://stackoverflow.com/questions/306313/is-operator-behaves-unexpectedly-with-integers (Personally I prefer the second answer better than the marked as best one)
6th Nov 2018, 11:16 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 6
a is b dont check if they store same content . Checks id of element. The answer can be undefined. Try a==b for comparing integers
6th Nov 2018, 11:08 PM
Anya
Anya - avatar
6th Nov 2018, 11:17 PM
Anya
Anya - avatar