Bird
0
0

In Python, what is the conventional meaning of prefixing an instance variable with a single underscore (e.g., _attribute)?

easy📝 Conceptual Q1 of 15
Python - Encapsulation and Data Protection
In Python, what is the conventional meaning of prefixing an instance variable with a single underscore (e.g., _attribute)?
AIt indicates the attribute is intended for internal use and should be treated as protected.
BIt makes the attribute private and inaccessible outside the class.
CIt automatically encrypts the attribute's value.
DIt declares the attribute as a class variable.
Step-by-Step Solution
Solution:
  1. Step 1: Understand Python naming conventions

    Python uses naming conventions to indicate intended usage of variables.
  2. Step 2: Single underscore prefix meaning

    A single underscore prefix signals that the attribute is intended for internal or protected use, but it is not enforced by Python.
  3. Final Answer:

    It indicates the attribute is intended for internal use and should be treated as protected. -> Option A
  4. Quick Check:

    Single underscore means 'protected' by convention [OK]
Quick Trick: Single underscore means 'protected' by convention [OK]
Common Mistakes:
  • Confusing single underscore with private attribute
  • Assuming Python enforces access restrictions
  • Thinking underscore encrypts or hides data

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes