小白教程
所有教程
关于
Search
172.70.130.239
172.70.130.239
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Python func hasattr”的源代码
本页内容
上一节:
Python_func_complex
下一节:
Python3_func_number_max
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:hasattr()}}[[Category:python3 built in functions|61]] = Python hasattr() 函数 = [[python built in functions|Python 内置函数]] == 描述 == '''hasattr()''' 函数用于判断对象是否包含对应的属性。 == 语法 == hasattr 语法: <sample title="" desc="" lang="python" hererun="1"> hasattr(object, name) </sample> == 参数 == * object -- 对象。 * name -- 字符串,属性名。 == 返回值 == 如果对象有该属性返回 True,否则返回 False。 以下实例展示了 hasattr 的使用方法: <sample title="" desc="" lang="python" hererun="1"> #!/usr/bin/python # -*- coding: UTF-8 -*- 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')) # 没有该属性 </sample> 输出结果: <sample title="" desc="" lang="python" hererun="1"> True True True False </sample> [[python built in functions|Python 内置函数]]
返回至“
Python func hasattr
”。
上一节:
Python_func_complex
下一节:
Python3_func_number_max