Python

Python Menu

Python

Python getattr() Function - Definition, Syntax, Parameters, Examples

Definition

The getattr() function returns the value of the specified attribute from the specified object.

Syntax

getattr(object, attribute, default)

Parameters

Parameter Description
object Required. An object.
attribute The name of the attribute you want to get the value from
default Optional. The value to return if the attribute does not exist

Examples

class Car: name = "Nissan" model = 1995 country = "Japan" myCar = getattr(Car, 'name') print(myCar)

Introduction

Python Basics

Python Advance

Data Science Python Tutorials

Python Functions and Methods