Python hasattr getattr

Publicado el: 31 marzo 2026
en el canal de: 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


En esta página del sitio puede ver el video en línea Python hasattr getattr de Duración hora minuto segunda en buena calidad , que subió el usuario Jakubication 31 marzo 2026, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 22 veces y le gustó 2 a los espectadores. Disfruta viendo!