Python hasattr getattr

Published: 31 March 2026
on channel: Jakubication
22
2

In Python, hasattr and getattr are both functions that deal with an object and its attributes. The hasattr function sees if an object contains a given attribute. The main utility of hasattr is being able to see if an object has a given attribute, without raising an attribute error. getattr's functionality is identical to using dot notation to access an object's given attribute directly. getattr and dot notation differ in a few different ways. First, by being able to access an object's attribute dynamically, via a string, instead of typing out the attribute name directly. Next, as a consequence of the previous one, being able to loop through a list of attributes. geattr has an optional third argument that allows you to check for an attribute that doesn't exist, and not get an AttributeError.

Sections
0:00 - hasattr
1:03 - getattr
2:59 - Outro

#python #codingtutorial #learntocode


On this page of the site you can watch the video online Python hasattr getattr with a duration of hours minute second in good quality, which was uploaded by the user Jakubication 31 March 2026, share the link with friends and acquaintances, this video has already been watched 22 times on youtube and it was liked by 2 viewers. Enjoy your viewing!