From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Sun, 25 Feb 2024 08:06:37 +0000 (+0100) Subject: [3.11] Add an example of of custom `__repr__` (GH-112761) (#115901) X-Git-Tag: v3.11.9~150 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c0789209c49167d563b5777966b40dca7f6411fb;p=thirdparty%2FPython%2Fcpython.git [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 5770006ffac2abd4f1c9fd33bf5015c9ef023576) Co-authored-by: Oh seungmin Co-authored-by: Terry Jan Reedy --- diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst index 1db280607954..086b3a3bee57 100644 --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -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)