Recall & Review
beginner
What is an instance method in Python?
An instance method is a function defined inside a class that operates on an instance of that class. It can access and modify the object's attributes using the 'self' parameter.Click to reveal answer
beginner
Why do instance methods use 'self' as their first parameter?
'self' represents the specific object calling the method. It allows the method to access or change the object's own data and other methods.
Click to reveal answer
beginner
How do you call an instance method on an object?
You call it using the dot notation: object.method_name(). Python automatically passes the object as 'self' to the method.
Click to reveal answer
beginner
Example: What will this code print?
class Dog:
def bark(self):
print('Woof!')
my_dog = Dog()
my_dog.bark()It will print: Woof!
Because 'bark' is an instance method called on 'my_dog', it prints 'Woof!'.
Click to reveal answer
intermediate
Can instance methods modify the object's attributes? How?
Yes, instance methods can change the object's attributes by using 'self.attribute_name = new_value'. This updates the data stored in that specific object.
Click to reveal answer
What does the 'self' parameter in an instance method represent?
✗ Incorrect
'self' always refers to the specific object that calls the instance method.
How do you define an instance method inside a class?
✗ Incorrect
Instance methods must have 'self' as the first parameter to access the object.
Which of these calls an instance method correctly?
✗ Incorrect
You call instance methods on an object using dot notation: obj.method()
Can instance methods access other methods in the same class?
✗ Incorrect
Instance methods can call other instance methods using self.other_method()
What happens if you forget to include 'self' in an instance method definition?
✗ Incorrect
Python expects 'self' as the first parameter; missing it causes errors when calling the method.
Explain what an instance method is and why 'self' is important.
Think about how methods know which object they belong to.
You got /3 concepts.
Describe how to call an instance method and what happens behind the scenes.
Remember the dot notation and the role of 'self'.
You got /3 concepts.