]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] Add an example of of custom `__repr__` (GH-112761) (#115900)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sun, 25 Feb 2024 08:05:39 +0000 (09:05 +0100)
committerGitHub <noreply@github.com>
Sun, 25 Feb 2024 08:05:39 +0000 (08:05 +0000)
Added to repr entry in Doc/library/functions.rst.

---------

(cherry picked from commit 5770006ffac2abd4f1c9fd33bf5015c9ef023576)

Co-authored-by: Oh seungmin <tmdals179@gmail.com>
Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
Doc/library/functions.rst

index fd16763b81d6312b62aa432774943beac2d0b3aa..fdc960c01d54b2f6c5c1658869a5c7c094a2da32 100644 (file)
@@ -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)