Function Details: hasattr

Description


Returns whether the object has an attribute with the given name.


Extended Description


The hasattr() function is used to determine if an object has a given attribute. It's equivalent to calling getattr(object, name) and seeing whether it raises an AttributeError or not.


Read More about hasattr from Python Documentation

Function Signature


hasattr(object: Any, name: str) -> bool

Module: builtins

Parameters



Parameter List


  • object: Any
  • name: str

Return


Returns True if the object has the given named attribute, False otherwise.


Return Type


bool

Output

Explanation

This example demonstrates how to use hasattr() to check for the existence of attributes in a class instance.