What does `__repr__` vs `__str__` represent in Python?

Python Professional Hard

Python Professional — Hard

What does `__repr__` vs `__str__` represent in Python?

Key points

  • `__repr__` is for developers, `__str__` is for users
  • `__repr__` focuses on unambiguous representation, `__str__` on readability
  • `__repr__` is used for debugging, `__str__` for user interaction

Ready to go further?

Related questions