Signature: hasattr(obj, name, /)
Docstring:
Return whether the object has an attribute with the given name.
This is done by calling getattr(obj, name) and catching AttributeError.
Type: builtin_function_or_method
就是问给定的对象, 有没有那个名字的属性
就像如下的例子, numpy.ndarray
对象有属性shape
,而没有属性shap
>>> import numpy as np
>>> ones = np.ones(1)
>>> ones
array([1.])
>>> hasattr(ones, 'shape')
True
>>> hasattr(ones, 'shap')
False