class MyObject(object): def __init__(self): self.x = 9 def power(self): return self.x * self.xobj = MyObject()fn = getattr(obj, 'power')setattr(obj, 'y', 19)print(hasattr(obj, 'x'))print(obj.x)print(hasattr(obj, 'y'))print(hasattr(obj, 'y') )print(getattr(obj, 'y'))print(getattr(obj, 'z', 404))print(hasattr(obj, 'power'))print(getattr(obj, 'power'))print(fn)print(fn())
Sign in to make a reply
好学者