Python领先的下划线_variables

Ari*_*ury 15 python

我们知道在类中,使用以下函数时__function__不会导入:

from module import *
Run Code Online (Sandbox Code Playgroud)

有人问什么是_variable?我从来没有一个.
它们存在吗?这是一个变量的概念,无法使用类对象或其他东西访问?

Tho*_*nan 21

它是私有变量的命名约定.请参见9.6,私有变量:http://docs.python.org/tutorial/classes.html#private-variables


Mat*_*ias 7

以下划线开头的变量名称强烈暗示该变量应被视为私有.

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