Difference between repr and str, and is and ==


Hi, in terms of Python 3 can you please explain the difference between:

is and ==

str and repr



is check identity, while == check if equal. So for example:

a = [1, 2, 3]
b = [1, 2, 3]
print(a is b) # false
print(a == b) # true


a = b =  [1, 2, 3]
print(a is b) # true
print(a == b) # true

now a is b is true, given both variables point to the same list in memory.

str vs repr is more difficult, as such better answers exist then i could write:


let me know if you have questions about it


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.