Python hasattr() function
Published February 16, 2022The Python hasattr() method is a built-in utility function that checks if an object has the specified named attribute and returns true if it does, otherwise false.
Syntax
The Python hasattr() method has the following syntax:
getattr(object, key, default) |
where:
Object: The object whose properties must be processed.
Key: an object's property
Default: the default value that must be displayed if the attribute is not found
Example
class Python: |
Output
Is python present ? True Is version present ? True |
Article Contributed By :
|
|
|
|
224 Views |