Lesson 34 of 55
15 mins readPython Static Members and Readonly Modifiers
In Plain English
Static members belong to the class constructor function itself rather than instances. Readonly fields can only be initialized at declaration or inside the constructor.
Core Rules to Remember

Static Members: Accessed via ClassName.member without creating class instances.

Readonly Fields: Guarantees property values cannot be mutated after construction.
Live Interactive Example
Hit Run Code to see it liveStatic Methods and Constants
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
Output Console
Click "Run Code" to view the rendered output.
How it works: Static properties are referenced via MathUtils and shared across all instances.
Your Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Micro Exercise
Create an Id Generator Factory
Create class IdFactory with private static nextId: number = 1000.
Add public static generate(prefix: string): string that returns `${prefix}_${IdFactory.nextId++}`.
Generate two IDs with prefix "req" and print them separated by ", ".
1
2
3
4
5
6
7
8
9
Sandbox Output
Click "Run & Check" to test your solution.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.