Python hasattr() function

The hasattr() function in Python returns a Boolean value ‘True’ if the given object has the specified attribute, else it returns False.

Syntax

Parameter

object: it is a required parameter which represents an object.

attribute: This parameter represents the name of the attribute you want to check if it exists.

Return

This function returns a Boolean value ‘True’ if the given object has the specified attribute

Example 1

Output

Example 2

Output

Pin It on Pinterest

Share This