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')来判断一个对象是否存在某个方法
时间: 2025-01-01 08:01:11
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')来判断一个对象是否存在某个方法