+ 3

What’s the difference between “is” and “==” in Python?

a = 'SoloLearn' b = 'SoloLearn' print(a == b) >>>True print(a is b) >>>True a = ['SoloLearn'] b = ['SoloLearn'] print(a is b) >>>False print(a == b) >>>True

30th Mar 2022, 6:08 AM
CodeStory
CodeStory - avatar
2 Answers
+ 6
== is for value equality. It's used to know if two objects have the same value. is is for reference equality. It's used to know if two references refer (or point) to the same object, i.e if they're identical.
30th Mar 2022, 6:13 AM
Jibran Abdul Jabbar
Jibran Abdul Jabbar - avatar
+ 4
30th Mar 2022, 6:17 AM
Ipang