__str__ VS __repr__ in Python — Same But Different

Liu Zuo Lin
Level Up Coding
Published in
3 min readApr 19, 2024

--

You deceitful liar, you teller of untruths, you phony fibster — how can something be same yet different? Being the same is the same as being not different. And conversely, being different is the same as not being the same. So which is which?

For the magic methods __str__ and __repr__, they are both the same and different, but in different contexts.

--

--