cekong

导航

python中下划线

引用: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(self):
    print("I'm a method in B")
b = B()
b.method()

#I'm a method in A


B.method()不能调用B.__method的方法
在我们创建一个以"__"两个下划线开始的方法时,这意味着这个方法不能被重写,它只允许在该类的内部中使用。

引用:https://www.cnblogs.com/coder2012/p/4423356.html

posted on 2018-12-12 09:15  cekong  阅读(113)  评论(0编辑  收藏  举报