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(x,'call')来判断一个对象是否存在某个方法
时间: 2024-10-29 10:46:48
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(x,'call')来判断一个对象是否存在某个方法