Bird
Raised Fist0

Find the error in this code:

medium📝 Debug Q6 of Q15
Python - Class Methods and Static Methods
Find the error in this code:
class Sample:
    @classmethod
    def info(self):
        return 'Info'
AMissing @staticmethod decorator
BFirst parameter should be cls, not self
CMethod must have no parameters
DClass methods cannot return strings
Step-by-Step Solution
Solution:
  1. Step 1: Check the first parameter of a class method

    Class methods must have 'cls' as the first parameter, not 'self'.
  2. Step 2: Identify the error in the code

    The method uses 'self' instead of 'cls', which is incorrect for class methods.
  3. Final Answer:

    First parameter should be cls, not self -> Option B
  4. Quick Check:

    Class method first parameter = cls [OK]
Quick Trick: Use cls, not self, for class method first parameter [OK]
Common Mistakes:
MISTAKES
  • Using self in class methods
  • Confusing decorators
  • Assuming no parameters needed

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes