Python getattr() Function for getting the value of a class attribute.

Charan H U
Oct 11, 2022

--

Python getattr() Function: The getattr() function returns the value of the specified attribute (property or method) from the specified object.

If the specified attribute does not exist, default value is returned.

Syntax: getattr(object, attribute, default)

Parameters:

object: object whose attribute is to be returned

attribute: attribute name whose value is to be returned

default: default value to be returned if the attribute does not exist

Return Value: value of the specified attribute

--

--

Charan H U
Charan H U

Written by Charan H U

Applied AI Engineer | Internet Content Creator

No responses yet