__str__
__str__ is a Python special method that returns an object's informal, human-readable string representation.
Python How-To
__str__ is a Python special method that returns an informal, user-oriented string representation of an object.
- How it is used
- Makes printed instances and f-string interpolation display meaningful, user-oriented information.
- How deep it goes
- Works through an instance-method implementation, its str return value, invocation paths, and its distinction from __repr__.
- Examples
- Shows a Task with title, description, and urgency, plus a Direction enumeration displayed as a lowercase direction.
- What you can do after
- Build it from scratch: define __str__ for a class or enumeration to produce readable instance output.
Python Workout: 50 ten-minute exercises
A Python special method that returns an object's user-oriented string representation.
- How it is used
- Explains how objects can provide readable user-facing representations alongside developer-oriented representations.
- How deep it goes
- Defines the audience distinction and shows a Bowl example, but defers deeper object-model mechanics.
- Examples
- Uses Bowl and Scoop objects, numeric conversion with str(5), and joining converted ranges.
- What you can do after
- Apply it via Python string conversion and object representation choices for readable output.
Read how Python Workout: 50 ten-minute exercises explains __str__ →
The Quick Python Book, Fourth Edition
__str__ is Python's special method for producing an informal string representation of an object.
- How it is used
- Uses __str__ to make custom objects readable during printing, debugging, and conversion to user-facing strings.
- How deep it goes
- Explains automatic invocation and demonstrates formatting and recursive delegation, without covering lower-level implementation details.
- Examples
- Demonstrates RGB Color formatting, printed Circle descriptions, and recursive HTML document rendering.
- What you can do after
- Apply it via print() and str() to produce informative representations of custom class instances.
Read how The Quick Python Book, Fourth Edition explains __str__ →
Related concepts
- printused by · Print is a programming operation that writes a value or its textual representation to an output destination, often standard output.
- __repr__contrasts with · __repr__ is a Python special method that returns an object’s developer-oriented string representation, ideally unambiguous and suitable for recreating an equivalent object.
- special methodkind of · A special method is a Python method with a conventionally reserved name that defines an object's behavior for language operations or built-in functions.
- stringproduces · A string is a programming-language value representing an ordered sequence of characters or character units as text.
- comprehensionused by · A comprehension is a language construct that creates a collection by iterating over one or more sources, optionally filtering elements and transforming them.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.


