From 6b1042a7347a33f7415d357601dc3c8cf1b22bbb Mon Sep 17 00:00:00 2001 From: Manoj Date: Sun, 12 Apr 2026 08:38:38 +0530 Subject: [PATCH 1/4] Added Examples for Private Mangling --- Doc/tutorial/classes.rst | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Doc/tutorial/classes.rst b/Doc/tutorial/classes.rst index 4f7da5253f78bc..a64ca99047a7d5 100644 --- a/Doc/tutorial/classes.rst +++ b/Doc/tutorial/classes.rst @@ -689,7 +689,23 @@ such a mechanism, called :dfn:`name mangling`. Any identifier of the form is textually replaced with ``_classname__spam``, where ``classname`` is the current class name with leading underscore(s) stripped. This mangling is done without regard to the syntactic position of the identifier, as long as it -occurs within the definition of a class. +occurs within the definition of a class. For example: + +.. code-block:: python + + class Employee: + __dept = 'computer lab' + def __detail(self): + # __dept is a private variable,so we access it with _Employee__dept + print('Employee is from',self._Employee__dept) + +.. code-block:: pycon + + >>> john = Employee() + >>> john._Employee__dept + 'computer lab' + >>> john._Employee__detail() + Employee is from computer lab .. seealso:: From 49edf98f91e363c141d3c660e9db7cb925e5302a Mon Sep 17 00:00:00 2001 From: Manoj Date: Sun, 12 Apr 2026 08:55:10 +0530 Subject: [PATCH 2/4] Fixed Lint Issues by removing trailing whitespace --- Doc/tutorial/classes.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/tutorial/classes.rst b/Doc/tutorial/classes.rst index a64ca99047a7d5..bf41bf5ed2afaa 100644 --- a/Doc/tutorial/classes.rst +++ b/Doc/tutorial/classes.rst @@ -692,7 +692,7 @@ without regard to the syntactic position of the identifier, as long as it occurs within the definition of a class. For example: .. code-block:: python - + class Employee: __dept = 'computer lab' def __detail(self): From 1155918b1ec7e944c466075b32d48bdeda0687aa Mon Sep 17 00:00:00 2001 From: Manoj Date: Sun, 12 Apr 2026 13:51:29 +0530 Subject: [PATCH 3/4] Fixed Code Block under Private Variables --- Doc/tutorial/classes.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/tutorial/classes.rst b/Doc/tutorial/classes.rst index bf41bf5ed2afaa..1dc1b3a0750649 100644 --- a/Doc/tutorial/classes.rst +++ b/Doc/tutorial/classes.rst @@ -697,7 +697,7 @@ occurs within the definition of a class. For example: __dept = 'computer lab' def __detail(self): # __dept is a private variable,so we access it with _Employee__dept - print('Employee is from',self._Employee__dept) + print('Employee is from',self.__dept) .. code-block:: pycon From c4c73edfb5c8bd3cd30de8e0c13479f8e3b6dfde Mon Sep 17 00:00:00 2001 From: Manoj Date: Sun, 12 Apr 2026 13:52:13 +0530 Subject: [PATCH 4/4] Fixed Code Block under Private Variables --- Doc/tutorial/classes.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/Doc/tutorial/classes.rst b/Doc/tutorial/classes.rst index 1dc1b3a0750649..83162334b7707e 100644 --- a/Doc/tutorial/classes.rst +++ b/Doc/tutorial/classes.rst @@ -696,7 +696,6 @@ occurs within the definition of a class. For example: class Employee: __dept = 'computer lab' def __detail(self): - # __dept is a private variable,so we access it with _Employee__dept print('Employee is from',self.__dept) .. code-block:: pycon