18

We know that in a class, functions starting with __function__ do not get imported while using:

from module import *

Someone asked what is an _variable? I have never used one.
Do they exist? Is this a concept of variable which cannot be accessed using class object or something?

Arindam Roychowdhury
  • 5,927
  • 5
  • 55
  • 63
  • 3
    Possible duplicate of [What is the meaning of a single- and a double-underscore before an object name?](http://stackoverflow.com/questions/1301346/what-is-the-meaning-of-a-single-and-a-double-underscore-before-an-object-name) – MackM Apr 12 '17 at 16:58

2 Answers2

25

It is a naming convention for private variables. See 9.6, private variables: http://docs.python.org/tutorial/classes.html#private-variables

Thomas Dignan
  • 7,052
  • 3
  • 40
  • 48
7

A variable name starting with an underscore is a strong hint that this variable should be viewed as private.

Read http://docs.python.org/tutorial/classes.html#private-variables

Matthias
  • 12,873
  • 6
  • 42
  • 48