Bird
Raised Fist0

Why must the first parameter of instance methods in Python classes be named self (by convention)?

hard🧠 Conceptual Q10 of Q15
Python - Classes and Object Lifecycle
Why must the first parameter of instance methods in Python classes be named self (by convention)?
AIt is a keyword required by Python syntax
BIt is optional and can be omitted
CIt refers to the instance calling the method, allowing access to attributes
DIt is used to define class variables
Step-by-Step Solution
Solution:
  1. Step 1: Understand role of self parameter

    self represents the instance object that calls the method.
  2. Step 2: Explain why self is needed

    It allows methods to access or modify the instance's attributes and other methods.
  3. Final Answer:

    It refers to the instance calling the method, allowing access to attributes -> Option C
  4. Quick Check:

    self = instance reference in methods [OK]
Quick Trick: self links method to the calling object [OK]
Common Mistakes:
MISTAKES
  • Thinking self is a Python keyword
  • Believing self is optional
  • Confusing self with class variables

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes