hasattr函数的用法

class variable:
  x = 1
  y = 'a'
  z = True

dd = variable()
print(hasattr(dd, 'x'))
print(hasattr(dd, 'y'))
print(hasattr(dd, 'z'))
print(hasattr(dd, 'no'))

True
True
True
False

posted @ 2022-02-16 20:00  小丑_jk  阅读(170)  评论(0编辑  收藏  举报