Skip to content

Commit 5770006

Browse files
Add an example of of custom __repr__ (#112761)
Added to repr entry in Doc/library/functions.rst. --------- Co-authored-by: Terry Jan Reedy <[email protected]>
1 parent f745586 commit 5770006

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

Doc/library/functions.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1569,6 +1569,16 @@ are always available. They are listed here in alphabetical order.
15691569
If :func:`sys.displayhook` is not accessible, this function will raise
15701570
:exc:`RuntimeError`.
15711571

1572+
This class has a custom representation that can be evaluated::
1573+
1574+
class Person:
1575+
def __init__(self, name, age):
1576+
self.name = name
1577+
self.age = age
1578+
1579+
def __repr__(self):
1580+
return f"Person('{self.name}', {self.age})"
1581+
15721582

15731583
.. function:: reversed(seq)
15741584

0 commit comments

Comments
 (0)