mirror of https://github.com/python/cpython
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>
This commit is contained in:
parent
f7455864f2
commit
5770006ffa
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue