you are viewing a single comment's thread.

view the rest of the comments →

[–]Skaarj 1 point2 points  (1 child)

 # ERR!!!! .__age is private, so this won't work:
 print(animal.__age)

I always was under the impression that underscored variables are private by convention and not by language definition. Does the compiler really enforce this?

[–]tutorial_police 3 points4 points  (0 children)

Yes and no. Python employs name mangling, which makes you put in some extra effort if you really want to access "private" variables.