about private and protected scope in python

This commit is contained in:
Hizenberg469
2025-03-13 13:47:22 +05:30
parent 0ce49095d6
commit 98558bab53

View File

@@ -51,16 +51,20 @@
keyword which acts like a this pointer
but in @staticmethod we can't do that.
-> private variable:
-> protected variable and function:
python doesn't provide any means to limit the access of data members
of class. The only thing smart is to use convention.
Any variable with underscore means it's a private variable and
Any variable with underscore means it's a protected variable and
don't modify it.
Same goes for function in a class (methods).
For ex:
_name is private variable in a class.
_name is protected variable in a class.
_getName() is protected function in a class.
-> Inheritance:
@@ -155,3 +159,16 @@
MRO allow us to determine the order in which
the Inheritance need to be processed. This
order is determined using Depth first search.
-> private variable and function:
Any variable with double underscore means it's a protected variable and
don't modify it.
Same goes for function in a class (methods).
For ex:
__name is protected variable in a class.
__modifyName() is protected function in a class.