A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.w3schools.com/python/ref_func_getattr.asp below:

Website Navigation


Python getattr() Function

Python getattr() Function

❮ Built-in Functions

Example

Get the value of the "age" property of the "Person" object:

class Person:

name = "John"

age = 36

country = "Norway"

x = getattr(Person, 'age')


Try it Yourself » Definition and Usage

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

Syntax

getattr(object, attribute, default)

Parameter Values 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 More Examples Example

Use the "default" parameter to write a message when the attribute does not exist:

class Person:

name = "John"

age = 36

country = "Norway"

x = getattr(Person, 'page', 'my message')


Try it Yourself » Related Pages

The delattr() function, to remove an attribute

The hasattr() function, to check if an attribute exist

The setattr() function, to set the value of an attribute

❮ Built-in Functions

Track your progress - it's free!


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4