Skip to content

Commit

Permalink
Add an example of of custom __repr__ (python#112761)
Browse files Browse the repository at this point in the history
Added to repr entry in Doc/library/functions.rst.

---------

Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
  • Loading branch information
osmin625 and terryjreedy committed Feb 25, 2024
1 parent f745586 commit 5770006
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Doc/library/functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 5770006

Please sign in to comment.