Thursday 12 July 2018

Python Object Attribute Variable Names Beginning With a Single Underscore

Cited from the book "Python How to Program"

Attribute names that begin with a single underscore have no special meaning in the syntax of the Python language itself. However, the single leading underscore is a convention among Python programmers who use the class. When a class author creates an attribute with a single leading underscore, the author does not want users of the class to access the attribute directly. If a program requires access to the attributes, the class author provides some other means for doing so. In this case, we provide access methods through which clients should manipulate the data.

No comments:

Post a Comment