class Coordinate:
x = 10
y = -5
z = 0
point1 = Coordinate()
print(hasattr(point1, 'x'))
print(hasattr(point1, 'y'))
print(hasattr(point1, 'z'))
print(hasattr(point1, 'no')) # 没有该属性
文档信息
- 本文作者:zhupite
- 本文链接:https://zhupite.com/python/python-hasattr.html
- 版权声明:自由转载-非商用-非衍生-保持署名(创意共享3.0许可证)