Mojo trait
StringRepresentable
The StringRepresentable
trait denotes a trait composition of the Stringable
and Representable
traits.
This trait is used by the format()
method to support both {!s}
(or {}
)
and {!r}
format specifiers. It allows the method to handle types that
can be formatted using both their string representation and their
more detailed representation.
Types implementing this trait must provide both __str__()
and __repr__()
methods as defined in Stringable
and Representable
traits respectively.
Implemented traits
AnyType
,
Representable
,
Stringable
Methods
__str__
__str__(self: T) -> String
Get the string representation of the type.
Returns:
The string representation of the type.
__repr__
__repr__(self: T) -> String
Get the string representation of the type instance, if possible, compatible with Mojo syntax.
Returns:
The string representation of the instance.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!