How to create Private members of Class?
If the name of a Python function, class method, or attribute starts with (but doesn't end with) two underscores, it's private; everything else is public.
class Test(object): __private_var = 100 public_var = 200 def __private_func(self): print('Private Function') def public_func(self): print('Public Function') print(self.public_var) def call_private(self): self.__private_func() print(self.__private_var) t = Test() print(t.call_private()) print(t.public_func())
Sample output of above program.
Private Function 100 None Public Function 200 None
2019-07-01T08:30:18+05:30
2019-07-01T08:30:18+05:30
Amit Arora
Amit Arora
Python Programming Tutorial
Python
Practical Solution