Bird
0
0

What does name mangling do to an attribute starting with double underscores in a Python class?

easy📝 Conceptual Q11 of 15
Python - Encapsulation and Data Protection
What does name mangling do to an attribute starting with double underscores in a Python class?
AIt adds the class name before the attribute name to avoid conflicts.
BIt makes the attribute public and accessible everywhere.
CIt deletes the attribute from the class.
DIt converts the attribute name to uppercase.
Step-by-Step Solution
Solution:
  1. Step 1: Understand double underscore prefix

    Attributes starting with double underscores trigger name mangling in Python classes.
  2. Step 2: Effect of name mangling

    Python adds the class name before the attribute name to avoid accidental access or conflicts.
  3. Final Answer:

    It adds the class name before the attribute name to avoid conflicts. -> Option A
  4. Quick Check:

    Name mangling = adds class name prefix [OK]
Quick Trick: Double underscores add class name prefix to attribute [OK]
Common Mistakes:
  • Thinking double underscores make attribute public
  • Confusing name mangling with deleting attributes
  • Assuming attribute name changes to uppercase

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes