mirror of
https://github.com/Hizenberg469/Python-tutorial.git
synced 2026-04-19 15:12:22 +03:00
about private and protected scope in python
This commit is contained in:
25
OOP/wiki.txt
25
OOP/wiki.txt
@@ -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:
|
||||
@@ -154,4 +158,17 @@
|
||||
|
||||
MRO allow us to determine the order in which
|
||||
the Inheritance need to be processed. This
|
||||
order is determined using Depth first search.
|
||||
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.
|
||||
|
||||
Reference in New Issue
Block a user