diff options
author | Oh seungmin <tmdals179@gmail.com> | 2024-02-25 07:59:35 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-25 07:59:35 (GMT) |
commit | 5770006ffac2abd4f1c9fd33bf5015c9ef023576 (patch) | |
tree | 0413de4355f0d867537fac23751ebc714bd0e0a5 /Doc/library | |
parent | f7455864f22369cc23bf3428624f310305cac999 (diff) | |
download | cpython-5770006ffac2abd4f1c9fd33bf5015c9ef023576.zip cpython-5770006ffac2abd4f1c9fd33bf5015c9ef023576.tar.gz cpython-5770006ffac2abd4f1c9fd33bf5015c9ef023576.tar.bz2 |
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>
Diffstat (limited to 'Doc/library')
-rw-r--r-- | Doc/library/functions.rst | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst index 27fce5a..a4852b9 100644 --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -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) |