Alex
Alex

Reputation: 636

Why in some modules, certain classes has two copies of the same method one starts with _?

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

Answers (1)

Sıddık Açıl
Sıddık Açıl

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.

Link for the above quote

Upvotes: 1

Related Questions