Introduction
In this lab, you will learn how to check if a class has a specific attribute in Python. The lab focuses on understanding class attributes, which are variables shared by all instances of a class, and differentiating them from instance attributes.
The lab guides you through creating a Dog
class with a class attribute species
and instance attributes name
and age
. You'll learn to access both types of attributes and observe how modifying a class attribute affects all instances. The lab will then introduce and utilize the hasattr()
and getattr()
functions to safely check for and access attributes within a class.