0

Operator Overloading : Code Coach

Help me with this problem. Couldn't figure out. https://code.sololearn.com/c4AYgEpRyWP9/?ref=app

31st May 2022, 7:53 AM
Hrithika Reddy
Hrithika Reddy - avatar
3 Answers
+ 1
Line 4: - Indentation error, should be at the same indent level with __init__() - Method name should be __add__() with double underscores Line 5: - Empty line should be removed Line 6: - Line should be properly indented as body of __add__() method def __init__(self, balance): self.balance = balance def __add__(self , other): return BankAccount(self.balance + other.balance)
31st May 2022, 8:37 AM
Ipang
+ 1
Thanks ❀❀ .
3rd Jun 2022, 6:12 AM
Hrithika Reddy
Hrithika Reddy - avatar
0
These are called 'dunder' methods. dunder as in Double UNDERscore. for operator + use '__add__' method like this https://code.sololearn.com/cNGAC4b3V9xU/?ref=app
31st May 2022, 8:34 AM
Vinit Sonawane
Vinit Sonawane - avatar