Identity vs Equality (is vs ==)
say it: “IZ VER-sus DUB-ul EE-kwulz” /ˈɪz ˈvɝsəs ˈdʌbəl ˈikwəlz/ or “eye-DEN-tih-tee VER-sus ih-KWAL-ih-tee” /aɪˈdɛntɪti ˈvɝsəs ɪˈkwɑlɪti/
== checks equal values; is checks the very same object.
What is the difference between is and ==?
== checks whether two values are equal. is checks whether they are the very same object. Use is mainly for None.
a = [1, 2]
b = [1, 2]
print(a == b) # True: same contents
print(a is b) # False: two separate lists
nickname = None
print(nickname is None) # True
Level: Journeyman · More Python terms at this level
Updated