Python - Encapsulation and Data ProtectionWhy does Python use name mangling for attributes starting with double underscores inside classes?ATo make attributes completely private and inaccessible from outside the class.BTo prevent accidental access and override in subclasses by changing attribute names internally.CTo optimize memory usage by shortening attribute names.DTo allow attributes to be accessed globally without restrictions.Check Answer
Step-by-Step SolutionSolution:Step 1: Purpose of name manglingIt changes attribute names internally to avoid accidental name clashes in subclasses.Step 2: Clarify privacy levelIt does not make attributes fully private; access is still possible with mangled names.Final Answer:To prevent accidental access and override in subclasses by changing attribute names internally. -> Option BQuick Check:Name mangling = avoid subclass conflicts, not full privacy [OK]Quick Trick: Name mangling prevents accidental overrides, not full privacy [OK]Common Mistakes:MISTAKESThinking name mangling enforces strict privacyBelieving it optimizes memoryAssuming it allows global access
Master "Encapsulation and Data Protection" in Python9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Python Quizzes Constructors and Object Initialization - __init__ method behavior - Quiz 4medium File Handling Fundamentals - Reading file data - Quiz 8hard Methods and Behavior Definition - Modifying object state - Quiz 4medium Modules and Code Organization - Importing specific items - Quiz 11easy Object-Oriented Programming Foundations - Procedural vs object-oriented approach - Quiz 13medium Object-Oriented Programming Foundations - Why object-oriented programming is used - Quiz 14medium Polymorphism and Dynamic Behavior - Polymorphism through functions - Quiz 11easy Polymorphism and Dynamic Behavior - Polymorphism through functions - Quiz 12easy Structured Data Files - Working with JSON files - Quiz 11easy Structured Data Files - Why structured data formats are used - Quiz 5medium