From: Oh seungmin Date: Sun, 25 Feb 2024 07:59:35 +0000 (+0900) Subject: Add an example of of custom `__repr__` (#112761) X-Git-Tag: v3.13.0a5~257 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5770006ffac2abd4f1c9fd33bf5015c9ef023576;p=thirdparty%2FPython%2Fcpython.git Add an example of of custom `__repr__` (#112761) Added to repr entry in Doc/library/functions.rst. --------- Co-authored-by: Terry Jan Reedy --- diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst index 27fce5aa0f1a..a4852b922b65 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)