Reputation:
I am working with python for a short while and want to be clear on how to use python visibility properties such as objects and methods.
I know that
self.any
is going to be public
self._any
(an underscore) is going to be protected
self.__any
(double underscores) is going to be private
I can understand the meaning but I have one doubt in using self._any
Protected in PHP will be possible in only parent and child class where public is not.
But in python I can call protected from everywhere too.
Let say:
class Test(object):
def __init__(self)
self._any = 'Anything'
Test()._any # 'Anything'
Pls help explain this or give some examples regarding protected objects and methods.
Upvotes: 0
Views: 1067
Reputation: 2569
In python private and protected method are only concepts. The implementation of protected method is only provided for development help, but it's not really a protected method as we can still access its value. And it's especially true for private method. See links under your post.
Upvotes: 1