0
0
Pythonprogramming~20 mins

Difference between method types in Python - Practice Questions

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Method Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of instance method call
What is the output of this code when calling obj.instance_method()?
Python
class MyClass:
    def instance_method(self):
        return 'instance method called'

obj = MyClass()
print(obj.instance_method())
ATypeError: instance_method() missing 1 required positional argument: 'self'
Binstance method called
CMyClass.instance_method
DNone
Attempts:
2 left
💡 Hint
Instance methods receive the instance automatically as the first argument.
Predict Output
intermediate
2:00remaining
Output of class method call
What is the output of this code when calling MyClass.class_method()?
Python
class MyClass:
    @classmethod
    def class_method(cls):
        return f'class method called from {cls.__name__}'

print(MyClass.class_method())
ANone
BTypeError: class_method() missing 1 required positional argument: 'cls'
Cclass method called from MyClass
Dclass method called from cls
Attempts:
2 left
💡 Hint
Class methods receive the class itself as the first argument.
Predict Output
advanced
2:00remaining
Output of static method call
What is the output of this code when calling MyClass.static_method()?
Python
class MyClass:
    @staticmethod
    def static_method():
        return 'static method called'

print(MyClass.static_method())
Astatic method called
BTypeError: static_method() missing 1 required positional argument
CMyClass.static_method
DNone
Attempts:
2 left
💡 Hint
Static methods do not receive any automatic first argument.
Predict Output
advanced
2:00remaining
Error when calling instance method on class
What error occurs when calling MyClass.instance_method() without an instance?
Python
class MyClass:
    def instance_method(self):
        return 'instance method called'

print(MyClass.instance_method())
ATypeError: instance_method() missing 1 required positional argument: 'self'
BAttributeError: 'MyClass' object has no attribute 'instance_method'
Cinstance method called
DNone
Attempts:
2 left
💡 Hint
Instance methods require an instance to be called.
🧠 Conceptual
expert
2:00remaining
Identify method type from behavior
Which method type does NOT receive any automatic first argument and behaves like a regular function inside the class?
AInstance method
BClass method
CAbstract method
DStatic method
Attempts:
2 left
💡 Hint
Think about which method type does not get self or cls automatically.