Challenge - 5 Problems
Method Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2: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())
Attempts:
2 left
💡 Hint
Instance methods receive the instance automatically as the first argument.
✗ Incorrect
Instance methods receive the instance (obj) as the first argument named self, so calling obj.instance_method() works and returns the string.
❓ Predict Output
intermediate2: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())
Attempts:
2 left
💡 Hint
Class methods receive the class itself as the first argument.
✗ Incorrect
Class methods receive the class (MyClass) as the first argument named cls, so calling MyClass.class_method() returns the formatted string.
❓ Predict Output
advanced2: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())
Attempts:
2 left
💡 Hint
Static methods do not receive any automatic first argument.
✗ Incorrect
Static methods behave like regular functions inside the class namespace and do not receive self or cls automatically.
❓ Predict Output
advanced2: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())
Attempts:
2 left
💡 Hint
Instance methods require an instance to be called.
✗ Incorrect
Calling an instance method on the class without passing an instance causes a TypeError because self is missing.
🧠 Conceptual
expert2: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?
Attempts:
2 left
💡 Hint
Think about which method type does not get self or cls automatically.
✗ Incorrect
Static methods do not receive self or cls automatically and behave like normal functions inside the class namespace.