Bird
0
0

Why might you choose a class method over a static method when creating alternative constructors in Python?

hard📝 Conceptual Q10 of 15
Python - Class Methods and Static Methods
Why might you choose a class method over a static method when creating alternative constructors in Python?
AClass methods do not require the cls parameter
BStatic methods automatically receive the instance
CStatic methods can modify class attributes
DClass methods receive the class and can create instances properly
Step-by-Step Solution
Solution:
  1. Step 1: Understand alternative constructors

    Alternative constructors create new instances and need to call the class.
  2. Step 2: Compare class and static methods

    Class methods receive cls, allowing them to create new instances correctly.
  3. Final Answer:

    Class methods receive the class and can create instances properly -> Option D
  4. Quick Check:

    Alternative constructors use class methods = A [OK]
Quick Trick: Use class methods for alternative constructors [OK]
Common Mistakes:
  • Using static methods which lack cls parameter
  • Thinking static methods receive instance automatically

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes