引用:https://blog.csdn.net/tcx1992/article/details/80105645?from=timeline Python中下划线的5种含义 class A(object): def __method(self): print("I'm a method in A") def method(self): self.__method()a = A()a.method()#I'm a method in A class B(A): def __method…
1. 作为一个名称:在代码中使用一个名称,但是在后面的代码中不再会使用到的时候,就可以使用_作为临时名称. n = 42 for _ in range(n): do_something() 2. 名称前的单下划线:类似于"私有",不能通过import 导入 3. 名称前的双下划线:对解释器来说有特殊意义,在解释执行的时候,会解释为"_classname__name",也就是在名称前面加上"_类名",这样做的目的是不和子类中的同名变量/方法冲突,也…