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 the class. It takes <code>self</code> as the first parameter, which refers to the specific object calling the method.Click to reveal answer
beginner
What is a class method in Python?A class method is a method that takes the class itself as the first argument, usually named <code>cls</code>. It is marked with the <code>@classmethod</code> decorator and can access or modify class state shared by all instances.Click to reveal answer
beginner
What is a static method in Python?
A static method is a method inside a class that does not take <code>self</code> or <code>cls</code> as the first parameter. It behaves like a regular function but belongs to the class's namespace. It is marked with the <code>@staticmethod</code> decorator.Click to reveal answer
intermediate
How do instance, class, and static methods differ in how they are called?
Instance methods are called on objects and receive the object as <code>self</code>. Class methods are called on the class and receive the class as <code>cls</code>. Static methods can be called on the class or instance but do not receive any automatic first argument.Click to reveal answer
intermediate
Why use a class method instead of an instance method?Use a class method when you need to access or modify class-level data that is shared across all instances, or when you want to create alternative constructors. Instance methods are for behavior related to individual objects.Click to reveal answer
Which method type automatically receives the instance as the first argument?
✗ Incorrect
Instance methods receive the instance (self) automatically when called on an object.
Which decorator is used to define a class method?
✗ Incorrect
The @classmethod decorator marks a method as a class method.
What is true about static methods?
✗ Incorrect
Static methods behave like regular functions inside the class and do not receive self or cls automatically.
When would you use a class method?
✗ Incorrect
Class methods are used to work with class-level data shared by all instances.
Which method type can be called on both the class and its instances?
✗ Incorrect
Static methods can be called on the class or instances without receiving any automatic argument.
Explain the differences between instance, class, and static methods in Python.
Think about what each method receives as the first parameter and what data it can access.
You got /3 concepts.
When should you choose to use a class method over an instance method?
Consider the difference between data that belongs to the whole class versus data that belongs to one object.
You got /3 concepts.