# P11.4 Python Inheritance चा पाया उदाहरणासह

Source: https://ravindrabagale.com/mr/datascience/py11-python-classes-and-objects-for-beginners-oop-basics/p11-4-python-inheritance-basics-with-an-example.html
Language: mr (Marathi with English technical terms)

हे का शिकायचं?

Savings account हा account च आहे, फक्त interest जास्त. सगळं पुन्हा लिहायची गरज नाही.

हे काय आहे?

class Child(Parent): parent च्या सगळ्या methods घेतो आणि नवीन जोडू शकतो. super() parent चा code चालवतो.

कसं करायचं?

Step 1. class Child(Parent): लिहा.
Step 2. super().__init__() call करा.
Step 3. नवीन method जोडा.

Python आणि इतर भाषा: तुलना

- Python: class Account:  def __init__(self, holder): ...
- Java: class Account { Account(String holder) { ... } }
- JavaScript: class Account { constructor(holder) { ... } }
- Go: type Account struct { Holder string }  (no classes, uses structs)

उदाहरण A: Savings account

```python
class Account:
    def __init__(self, holder, balance=0):
        self.holder = holder
        self.balance = balance
    def deposit(self, amount):
        self.balance += amount

class Savings(Account):
    def __init__(self, holder, balance=0, rate=0.03):
        super().__init__(holder, balance)
        self.rate = rate
    def add_interest(self):
        self.balance += self.balance * self.rate

s = Savings("Niamh", 1000)
s.deposit(500)
s.add_interest()
print(s.balance)
```

Output:

```text
1545.0
```

याचा अर्थ: Child class ने parent चे methods वापरले आणि interest ची नवीन method जोडली.

रवींद्र बागले यांची tip

Data work मध्ये तुम्ही बहुतेक इतरांनी लिहिलेले classes वापराल (DataFrame, Series). Basics पुरेसे — गरजेपेक्षा जास्त गुंतागुंत करू नका.
