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!
If you'd like to share more information, please report an issue on GitHub
π What went wrong?