Python 101 : Naming style - Underscores and double underscores -


Names that start and end with two underscores - __var__ - are internal names used by python like - __init__, __str__ -.

Names that start with an underscore - _var - are not imported into other programs using the - from ... import ... - instruction.
They are meant to be used within the program as "internals":


Names that start with two underscores - __var - inside a class get prefixed with the class name:


The "__var" variable becomes "_A__var".

The name that is represented by single underscore - _ - is used by python to store the result of the last result, for example to go through a loop where the index is of no use to us:


Names with a trailing underscore - var_ - are usually used so the name doesn't get mixed up with a python keyword.

Comments

Popular posts from this blog

Istio 101 : How Istio ServiceEntry relates to Kubernetes Services and Endpoints

Kubernetes 101 : - Scaling a Stateful set -

Python 101 : Generators and Lists