Python内置函数(27)——hasattr,,英文文档:hasat
Python内置函数(27)——hasattr,,英文文档:hasat
英文文档:
hasattr(object, name)The arguments are an object and a string. The result is True if the string is the name of one of the object’s attributes, False if not. (This is implemented by calling getattr(object, name) and seeing whether it raises an AttributeError or not.)说明: 1. 函数功能用来检测对象object中是否含有名为name的属性,如果有则返回True,如果没有返回False#定义类A>>> class Student: def __init__(self,name): self.name = name >>> s = Student(‘Aim‘)>>> hasattr(s,‘name‘) #a含有name属性True>>> hasattr(s,‘age‘) #a不含有age属性False
2. 函数实际上是调用getattr(object,name)函数,通过是否抛出AttributeError来判断是否含有属性。
Python内置函数(27)——hasattr
相关内容
- Python 3.6 安装后需要安装的常用 {控件}?,python3.6
- 转:对比python 链接 neo4j 驱动,py2neo 和 neo4j-driver 和 neo
- python安装pyautogui遇到的"gbk"异常解决,,一
- python 数据类型之间的转换,python数据类型,python内置数
- Python:strip 函数的陷阱,,S.strip(ch
- 【python】入门学习(三),,for循环for i
- python练习册0005,python0005, 第 0005 题:
- Centos 6.4升级Python 2.6.6到Python 3.3.3,centos2.6.6,ssh终端登录
- python数据库连接池,python数据库连接,一 DBUtils的
- python 迭代器,,迭代器使用方法:#!
评论关闭