PGoCareerGoCareer prep tools
Home
LoginSign up
  • Java
  • Python
  • AI
  • React
  • Angular
  • PHP
  • Node.js
  • SQL
  • DSA
  • HTML
  • CSS
  • JS
  • Spring
  • ML
  • MongoDB

Python · Theory

Access Modifiers in Python

← All stacks

Theory

60/268

Access Modifiers in Python

Python uses naming conventions more than private keywords. normal_name is public. _name means “internal / subclass, please don’t touch” — convention only. __name inside a class triggers name mangling so outside access is harder. There is no true private like Java. Culture: we’re all adults, follow the underscore.

Viva — explain _, __, and that privacy is by convention. Don’t claim __ makes it encrypted. It only mangles the name.

Access Modifiers in Python — output — 1 2. pub and _hint readable. __hide is name-mangled — don’t touch from outside.

Exam tip

_ vs __ difference.

Example

# Access modifiers
class A:
    def __init__(self):
        self.pub = 1
        self._hint = 2
        self.__hide = 3

a = A()
print(a.pub, a._hint)

Access Modifiers in Python — output: 1 2. pub and _hint readable. __hide is name-mangled — don’t touch from outside.

Short notes

  • DefPublic: normal names
  • Rule_ protected convention
  • Remember__ name mangling

Questions

1

Explain Access Modifiers as if you are teaching a junior — definition, then one tiny script.

2

What does the example print, and why?

3

What mistake do freshers make with Access Modifiers?

Previous← Encapsulation in PythonNextMethod Overloading in Python →
P

GoCareerGo

Utilities · Preparation Hub · Resume · CV · Tools — one workspace.

Workspace

DashboardProfilePreparation HubResume builderCV builderCareer planning

PDF Tools

Merge PDFSplit PDFCompress PDFImage to PDFAll toolsJobs

Image & QR

Compress ImageResize ImageQR ScannerQR GeneratorBlogIT interview prep

Company

FAQFeedbackContactPrivacyTermsSitemap

© 2026 GoCareerGo. Keep moving forward.