class Person:
def PrintName(self):
print 'Is a Person'
def PrintHello(self):
print 'Hello, world'
per = Person()
per.PrintName()
print hasattr(per,'PrintName')#True
本文介绍了Python中类的定义方法,包括成员函数的声明与调用,以及如何使用hasattr函数检查对象是否具有特定的方法。通过实例演示了类Person的创建、成员函数PrintName的调用,并验证了该对象是否拥有PrintName属性。
class Person:
def PrintName(self):
print 'Is a Person'
def PrintHello(self):
print 'Hello, world'
per = Person()
per.PrintName()
print hasattr(per,'PrintName')#True
转载于:https://www.cnblogs.com/Alexander11/p/4156199.html
679

被折叠的 条评论
为什么被折叠?