Bird
0
0

Why do instance attributes use 'self' in their definition inside a class?

hard📝 Conceptual Q10 of 15
Python - Classes and Object Lifecycle
Why do instance attributes use 'self' in their definition inside a class?
ATo call a static method
BTo define a class-wide variable
CTo refer to the specific object instance
DTo create a global variable
Step-by-Step Solution
Solution:
  1. Step 1: Understand the role of self

    Self refers to the current object instance, allowing access to its attributes and methods.
  2. Step 2: Differentiate from other uses

    Class variables and global variables do not use self; static methods do not use self either.
  3. Final Answer:

    To refer to the specific object instance -> Option C
  4. Quick Check:

    Self = current object instance reference [OK]
Quick Trick: Use self to access attributes of the current object [OK]
Common Mistakes:
  • Thinking self is a keyword for class variables
  • Confusing self with global or static context

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes