Difference between repr and str, and is and ==


#1

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

is and ==

str and repr

Thanks.


#2

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

and:

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:

https://stackoverflow.com/questions/1436703/difference-between-str-and-repr

let me know if you have questions about it


#3

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