Recall & Review
beginner
What are instance attributes in Python?
Instance attributes are variables that belong to a specific object created from a class. Each object can have different values for these attributes.
Click to reveal answer
beginner
How do you define an instance attribute inside a class?
You define instance attributes inside the __init__ method using self, like: <br>
self.attribute_name = value.Click to reveal answer
intermediate
What is the difference between instance attributes and class attributes?Instance attributes belong to each object separately, while class attributes are shared by all objects of the class.Click to reveal answer
intermediate
Can instance attributes be added outside the __init__ method?
Yes, you can add or change instance attributes anytime using dot notation, like
object.attribute = value.Click to reveal answer
beginner
What happens if you try to access an instance attribute that does not exist?
Python raises an AttributeError because the object does not have that attribute.
Click to reveal answer
Where are instance attributes usually defined in a Python class?
✗ Incorrect
Instance attributes are typically set inside the __init__ method using self to attach them to the object.
What keyword is used to refer to the current object inside a class?
✗ Incorrect
In Python, 'self' refers to the current object inside class methods.
If you change an instance attribute on one object, does it affect other objects of the same class?
✗ Incorrect
Instance attributes belong to each object separately, so changing one does not affect others.
What error occurs if you try to access a missing instance attribute?
✗ Incorrect
Accessing a non-existent attribute raises an AttributeError.
Can you add new instance attributes after an object is created?
✗ Incorrect
Python allows adding new instance attributes anytime using dot notation.
Explain what instance attributes are and how they differ from class attributes.
Think about how each object can have its own data.
You got /3 concepts.
Describe how to create and access instance attributes in a Python class.
Remember the role of self inside methods.
You got /3 concepts.