0

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.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
  • https://stackoverflow.com/questions/1301346/what-is-the-meaning-of-a-single-and-a-double-underscore-before-an-object-name – gstukelj Oct 23 '19 at 08:18
  • Possible duplicate of [What is the meaning of a single and a double underscore before an object name?](https://stackoverflow.com/questions/1301346/what-is-the-meaning-of-a-single-and-a-double-underscore-before-an-object-name) – Andreas Oct 23 '19 at 08:22

1 Answers1

1

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.

Florian Bernard
  • 2,561
  • 1
  • 9
  • 22