Source Code:
(back to article)
class MyClass: def __init__(self): self.attr = 1 obj = MyClass() if hasattr(obj, 'attr'): print('obj has attribute attr') else: print('obj does not have attribute attr')
Result:
Report an issue