mirror of
https://github.com/python/cpython.git
synced 2025-07-12 13:55:34 +00:00
[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 5770006ffa
)
Co-authored-by: Oh seungmin <tmdals179@gmail.com>
Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
This commit is contained in:
parent
92e43aea35
commit
c0789209c4
1 changed files with 10 additions and 0 deletions
|
@ -1568,6 +1568,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)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue