Home > Article > Backend Development > Can a python class call instance methods?
Can a python class call instance methods?
Instance methods. Except for static methods and class methods, all other methods of a class are instance methods.
Instance methods need to be called after instantiating the class. If you use the class to directly call the instance method, you need to explicitly pass in the instance as a parameter.
Related recommendations: "Python Video Tutorial"
The parameter self passed in on the leftmost side is the instance itself.
class ClassA(object): def func_a(self): print('Hello Python') if __name__ == '__main__': # 使用实例调用实例方法 ca = ClassA() ca.func_a() # 如果使用类直接调用实例方法,需要显式地将实例作为参数传入 ClassA.func_a(ca)
The above is the detailed content of Can a python class call instance methods?. For more information, please follow other related articles on the PHP Chinese website!