Introduction to the getattr function hasattr function and getattrhasattr function in python
Hasattr (object, name)
Purpose:Determine whether the object contains the feature named name (hasattr is implemented by calling getattr (ojbect, name) to
The following is a brief introduction to the getattr function hasattr function in python. I think this is quite good. now I will share it with you and give you a reference. Let's take a look at it with Xiaobian.
Hasattr (object,
Hasattr (object, name)
Action: Determines whether the object contains an attribute named name (Hasattr is implemented by calling GetAttr (Ojbect, name) to throw an exception.
Example:
>>> hasattr (list, ' append ') True >>> hasattr (list, ' Add ')
Class-Built-in functions
Services to classes and objects.
9 Built-in functions
Issubclass,isinstance,hasattr,getattr,setattr,delattr,dir,super,vars
Note: GetAttr () and delattr () may throw exceptions (such as Attributeerror) to handle exceptions
Hasattr (object, name) function:Determines whether an object has a Name property or a name method, returns a bool value, returns true with the Name property, or False otherwise.Note: name is enclosed in parentheses.classFunction_demo (): Name='Demo'
This article mainly introduces the functions of getattr and hasattr functions in Python. it is of great reference value. For more information, see hasattr (object, name)
Purpose: Determine whether the object contains the feature named name
Usage and understanding of hasattr ()--hasattr (obj, target)Determines whether the object obj contains, targets the target property, and then returns a Boolean value that returns True if there is no return false.>>> class School:... def __init__(
Python standard library: Detailed description of the use of the built-in function hasattr () getattr () setattr (), hasattrgetattrHasattr (object, name)
This function is used to determine whether the object property (name) exists. If the property
Hasattr (object, name)Determines whether an object has a Name property or a name method, returns a bool value, returns true with the name attribute, or FALSE.It is important to note that name is enclosed in parentheses.>>> class Test (): ...
This article through the sample code to give you a detailed introduction of Python3 in Hasattr (), GetAttr (), SetAttr (), delattr () function, very good, with reference value, need to refer to a friend
Hasattr () function
The Hasattr () function
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.