Unlike C++ or Java, Python doesn’t have strict restrictions for the permissions of attributes.
The Pythonic way to separate different permissions is to use underscores:
As the above code shows, we can define a protected attribute with a single leading underscore. This is just a convention. We can still use it as a public member. But we should not do this. Following good programming conventions will make our code more elegant and readable.
We define a private attribute with double-leading underscores. This mechanism is beyond convention. Python uses name mangling technique to ensure we won’t use a private member inappropriately.