Python标准库:内置函数hasattr(object, name)
来源:互联网 发布:51单片机的引脚功能 编辑:程序博客网 时间:2024/05/16 09:13
本函数是用来判断对象object的属性(name表示)是否存在。如果属性(name表示)存在,则返回True,否则返回False。参数object是一个对象,参数name是一个属性的字符串表示。
例子:
#hasattr()class Foo: def __init__(self): self.x = 123 def test(x): self.x = xfoo = Foo()print(hasattr(foo, 'x'))print(hasattr(foo, 'y'))print(hasattr(foo, 'test'))
输出结果如下:
True
False
True
蔡军生 QQ:9073204 深圳
0 0
- Python标准库:内置函数hasattr(object, name)
- Python标准库:内置函数hasattr(object, name)
- Python标准库:内置函数delattr(object, name)
- Python标准库:内置函数getattr(object, name[, default])
- Python标准库:内置函数setattr(object, name, value)
- python:hasattr(object, name)
- Python标准库:内置函数ascii(object)
- Python标准库:内置函数callable(object)
- Python标准库:内置函数dir([object])
- Python标准库:内置函数hash(object)
- Python标准库:内置函数help([object])
- Python标准库:内置函数id(object)
- Python标准库:内置函数object()
- Python标准库:内置函数repr(object)
- Python标准库:内置函数type(object)
- Python标准库:内置函数vars([object])
- Python标准库:内置函数vars([object])
- Python标准库:内置函数vars([object])
- [LeetCode]Majority Element
- Question2Answer的统计添加
- 【机器学习算法实现】主成分分析(PCA)——基于python+numpy
- Mybatis中实现oracle的批量插入、更新
- leetcode Longest Palindromic Substring
- Python标准库:内置函数hasattr(object, name)
- 2014_12_26
- 单例模式
- NSDictionary NSMutableDictionary的相关API总结
- 【CF189E】Weak Memory
- Linux man命令的使用方法
- Codeforces Round #181 (Div. 2)---C. Beautiful Numbers
- 推荐几个hadoop搭建的几个好的博文,亲测成功!
- poj1741 Tree