]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Add an example of of custom `__repr__` (#112761)
authorOh seungmin <tmdals179@gmail.com>
Sun, 25 Feb 2024 07:59:35 +0000 (16:59 +0900)
committerGitHub <noreply@github.com>
Sun, 25 Feb 2024 07:59:35 +0000 (02:59 -0500)
Added to repr entry in Doc/library/functions.rst.

---------

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

index 27fce5aa0f1a6366f9b19f0e9aeac8951383bada..a4852b922b65b3cda10f87ec9bdc7f34be039396 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)