PYTHON
Free Section Starter Challenge
30 min
10. Object-Oriented Python: Classes, Encapsulation & __init__
Overview: Model domain entities with classes, instance variables, private attributes, and custom methods.
Concept & Syntax Guide
Classes are blueprints for creating objects. The __init__ constructor initializes instance attributes attached to self. Prefixing attributes with a double underscore (e.g. __balance) invokes name mangling for private encapsulation.
Hands-On Practice Exercise
Construct BankAccount Object
Instantiate BankAccount with owner "Astro User" and deposit 5000, then print account summary.
Target Output:
Account Holder: Astro User, Balance: ₹5000
Need a hint? Click here to reveal
Hint: Check syntax carefully and make sure your code contains:
Account Holder: Astro User, Balance: ₹5000
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10