Add an example of of custom `__repr__` (#112761)

Added to repr entry in Doc/library/functions.rst.

---------

Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
This commit is contained in:
Oh seungmin 2024-02-25 16:59:35 +09:00 committed by GitHub
parent f7455864f2
commit 5770006ffa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 10 additions and 0 deletions

View File

@ -1569,6 +1569,16 @@ are always available. They are listed here in alphabetical order.
If :func:`sys.displayhook` is not accessible, this function will raise
:exc:`RuntimeError`.
This class has a custom representation that can be evaluated::
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
def __repr__(self):
return f"Person('{self.name}', {self.age})"
.. function:: reversed(seq)