1. 程式人生 > >python 定義類時,內部方法的互相呼叫

python 定義類時,內部方法的互相呼叫

每次呼叫內部的方法時,方法前面加 self.
舉例:

例子參考百度知道里面的回答

class MyClass:
    def __init__(self):
        pass
    def func1(self):
        # do something
        print('a')   #for example      
        self.common_func()
     def func2(self):
        # do something
        self.common_func()
         
     def
common_func(self): pass