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?
Enforced by the Python interpreter. Double Leading and Trailing Underscore( __var__ ): Indicates special methods defined by the Python language. Avoid this naming scheme for your own attributes. Single Underscore( _ ): Sometimes used as a name for temporary or insignificant variables (“don't care”).
The Python interpreter modifies the variable name with ___. So Multiple times It uses as a Private member because another class can not access that variable directly. The main purpose for __ is to use variable /method in class only If you want to use it outside of the class you can make it public.
Double underscores are used for fully private variables. According to Python documentation − If your class is intended to be subclassed, and you have attributes that you do not want subclasses to use, consider naming them with double leading underscores and no trailing underscores.
Rules for Python variables: A variable name must start with a letter or the underscore character. A variable name cannot start with a number. A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )
It is a naming convention for private variables. See 9.6, private variables: http://docs.python.org/tutorial/classes.html#private-variables
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With