Reputation: 636
Sometimes I see classes that has attributes or methods that start with underscore. Why do they do that?
For example: in Tensorflow, a model class has ._layers and .layers methods.
Upvotes: 0
Views: 47
Reputation: 967
Python has no notion of private members, so underscore is used as a convention to denote private methods or fields.
The underscore prefix is meant as a hint to another programmer that a variable or method starting with a single underscore is intended for internal use. This convention is defined in PEP 8.
Upvotes: 1