CertGrid CertGrid
Concepts·Certified Associate Python Programmer

Python Private Members and Name Mangling

The second half of PCAP objective 4.2. Python has no private keyword and no access control at all. What it has is a convention - one leading underscore means "internal" and is enforced by nothing - and a mechanism: two leading underscores make the compiler rename the attribute. The rename is real and examinable; the privacy is not.

Object-Oriented Python Guide 16 of 25 Intermediate

Name mangling has worked this way since Python 1 and is unchanged. There is no private, protected or public keyword in any version, and there is no plan for one.

One machine, and any shell with Python 3 will do - these exams test the language, not a distribution.
Server NameIP AddressOSRolesCPURAMHDD
RUNNER01192.168.0.27Ubuntu 26.04 LTSPython 3.14.4 - the only machine this path needs2 Core4 GB50 GB

This guide includes

Use this for the private-members half of the same objective. This matters because a double underscore hides nothing - the attribute is renamed rather than protected, and knowing the new name gets you straight back in.

Before you start

  1. One underscore, two underscores, none

  2. What the double underscore actually did

  3. Why the attribute name fails from outside

  4. Why the renaming exists

  5. The single underscore is only a convention

  6. Mangling applies to methods too

  7. What the exam does with this objective

Official sources