Python getattr() function

The getattr() function in Python returns the value of the named attribute for the given object.

Syntax

Parameter

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

name: This parameter represents the name of the attribute you want to get the value from.

default: It represents the value to return if the attribute does not exist.

Return

This function returns the value of the given attribute from the specified object.

Example 1

Output

Pin It on Pinterest

Share This