Bird
0
0

Why does Python use a single underscore prefix for protected attributes instead of enforcing access restrictions like some other languages?

hard📝 Conceptual Q10 of 15
Python - Encapsulation and Data Protection
Why does Python use a single underscore prefix for protected attributes instead of enforcing access restrictions like some other languages?
ABecause Python does not support any form of attribute protection.
BTo follow a convention that relies on programmer discipline rather than strict enforcement.
CTo make protected attributes completely private and inaccessible.
DTo automatically generate getter and setter methods.
Step-by-Step Solution
Solution:
  1. Step 1: Understand Python's philosophy

    Python prefers conventions and programmer responsibility over strict access control.
  2. Step 2: Compare with other languages

    Unlike languages with enforced private/protected keywords, Python uses naming conventions like single underscore to indicate protected status.
  3. Final Answer:

    To follow a convention that relies on programmer discipline rather than strict enforcement. -> Option B
  4. Quick Check:

    Python uses naming conventions, not enforced access control [OK]
Quick Trick: Python trusts programmers to respect naming conventions [OK]
Common Mistakes:
  • Thinking Python enforces access restrictions
  • Confusing protected with private
  • Assuming automatic method generation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes