__str__ and __repr__: Create a String Representation of a Python Object

__str__ and __repr__: Create a String Representation of a Python Object

If you want to create a string representation of an object, add __str__ and __repr__.

__str__ shows readable outputs when printing the object. __repr__ shows outputs that are useful for displaying and debugging the object.

Find an example of these two methods above.

Link to the source code.

Search

Scroll to Top

Work with Khuyen Tran

Work with Khuyen Tran