AI engineering glossary · Python advanced
What is __str__?
__str__: The special method returning a readable text form of an object for end users. It is used by print() and str(). If it is missing, Python falls back to __repr__.
__str__: an example
def __str__(self): return f'{self.name} (Rs {self.price})' prints a product as 'Pen (Rs 10)'.
Related terms
More Python advanced terms
Where you learn it
__str__ is part of the AI Engineering Program, which teaches it with notes, a hands-on lab and an exam. The first lesson is free.