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

Can a python class call instance methods?

爱喝马黛茶的安东尼
Release: 2019-06-18 15:09:07
Original
3251 people have browsed it

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)
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template