Home  >  Article  >  Backend Development  >  Can a python class call instance methods?

Can a python class call instance methods?

爱喝马黛茶的安东尼
爱喝马黛茶的安东尼Original
2019-06-18 14:24:333143browse

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.

Can a python class call 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn