+ 2

Python Data-hiding

In quiz 2/3 of Data-hiding section of Python course among the answers you can choose you have: - To mark it as private - To prevent it being called by external code but from a point of view of concept they're identical. When you mark a variable as private is seen only inside a class AND is inaccessible from outer code. isn't it?

17th Nov 2016, 1:01 PM
Riccardo M.
Riccardo M. - avatar
1 Réponse
+ 2
Ok. Just to clarify. From a concept point of view is like I write before. A private variable is invisible outside a class. In python "usually" use an underscore ( _ ) to consider a variable as "private". But it's still a public variable. But if you put two underscores ( __ ) Python as safety measure mark it as "private" to avoid erroneous overriding of methods/variables (but still reachable via _class__variable format)
17th Nov 2016, 1:21 PM
Riccardo M.
Riccardo M. - avatar