liveBook · Manning

String conversion

String conversion is an operation that transforms a value or representation into its textual string form according to language-defined rules.

How 2 Manning books explain it

The Well-Grounded Rubyist, Fourth Edition

String conversion is the derivation of a string or another object representing a string value in a different form.

How it is used
Provides object representations for output, interpolation, inspection, and regular-expression troubleshooting.
How deep it goes
Explains automatic calls, custom definitions, related methods, array exceptions, and regexp notation without exhaustive API coverage.
Examples
Uses irb expressions, a customized Object instance, array output, file output, and regular-expression representations.
What you can do after
Apply it via Ruby's to_s, puts, interpolation, inspect, display, and custom representation methods.

Read how The Well-Grounded Rubyist, Fourth Edition explains string conversion →

Python How-To

A string representation is textual output that describes the value or identity of an object.

How it is used
Improves object inspection, printed output, formatted display, and interactive console readability for class instances.
How deep it goes
Distinguishes __str__ from __repr__, specifies return requirements, and demonstrates both overrides with a Task class.
Examples
Uses a Task object with title, description, and urgency fields to demonstrate print, f-string interpolation, str(), repr(), and console display.
What you can do after
Build it from scratch by overriding __str__ and __repr__ for readable display and informative instance representations.

Read how Python How-To explains string conversion →

Related concepts

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.