Skip to content

Commit c078920

Browse files
miss-islingtonosmin625terryjreedy
authored
[3.11] Add an example of of custom __repr__ (GH-112761) (#115901)
Added to repr entry in Doc/library/functions.rst. --------- (cherry picked from commit 5770006) Co-authored-by: Oh seungmin <tmdals179@gmail.com> Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
1 parent 92e43ae commit c078920

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
@@ -1568,6 +1568,16 @@ are always available. They are listed here in alphabetical order.
15681568
If :func:`sys.displayhook` is not accessible, this function will raise
15691569
:exc:`RuntimeError`.
15701570

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

15721582
.. function:: reversed(seq)
15731583

0 commit comments

Comments
 (0)