What is the difference between __str__ and __repr__ in Python?

Python Developer Medium

Python Developer — Medium

What is the difference between __str__ and __repr__ in Python?

Key points

  • __str__ for human-readable output
  • __repr__ for unambiguous developer-facing representation
  • __repr__ should ideally recreate the object
  • __str__ focuses on readability

Ready to go further?

Related questions