中文字幕一区二区人妻电影,亚洲av无码一区二区乱子伦as ,亚洲精品无码永久在线观看,亚洲成aⅴ人片久青草影院按摩,亚洲黑人巨大videos

Python hasattr() 函數(shù)

Python 內置函數(shù) Python 內置函數(shù)


描述

hasattr() 函數(shù)用于判斷對象是否包含對應的屬性。

語法

hasattr 語法:

hasattr(object, name)

參數(shù)

  • object -- 對象。
  • name -- 字符串,屬性名。

返回值

如果對象有該屬性返回 True,否則返回 False。

實例

以下實例展示了 hasattr 的使用方法:

#!/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')) # 沒有該屬性

輸出結果:

True
True
True
False

Python 內置函數(shù) Python 內置函數(shù)

其他擴展