Lesson 32 of 55
15 mins readPython Access Modifiers: public, private, protected
In Plain English
Understand the visibility boundaries of class members: public, protected, private, and ECMAScript #private.
Core Rules to Remember

public / protected / private: TypeScript visibility modifiers enforced at compile time.

#private Fields: ECMAScript standard hard runtime encapsulation.
Live Interactive Example
Hit Run Code to see it liveEncapsulating Data with Modifiers
Python 3.12
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
Output Console
Click "Run Code" to view the rendered output.
How it works: protected members can be read within child classes, while private remains inaccessible outside BaseService.
Your Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Micro Exercise
Encapsulate User Credentials
Create class SafeUser with public username: string and private passwordHash: string.
Constructor sets both.
Add method verify(hash: string): boolean that checks this.passwordHash === hash.
Instantiate with "admin", "hash123", test verify("hash123"), and print result.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Sandbox Output
Click "Run & Check" to test your solution.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.