From 98558bab53902d26b545191e61dcccffe76c13be Mon Sep 17 00:00:00 2001 From: Hizenberg469 Date: Thu, 13 Mar 2025 13:47:22 +0530 Subject: [PATCH] about private and protected scope in python --- OOP/wiki.txt | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/OOP/wiki.txt b/OOP/wiki.txt index 59c3f34..d7778f0 100644 --- a/OOP/wiki.txt +++ b/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. \ No newline at end of file + 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.