|
| 1 | +''' |
| 2 | +When we put a double underscore in front of the attribute name, python will internally change its name to _Classname__attribute. |
| 3 | + |
| 4 | +Since we know that the name of the variable changes when we make it private, we can access it using its modified name as shown below: |
| 5 | +''' |
| 6 | +class Customer: |
| 7 | + def __init__(self, cust_id, name, age, wallet_balance): |
| 8 | + self.cust_id = cust_id |
| 9 | + self.name = name |
| 10 | + self.age = age |
| 11 | + self.__wallet_balance = wallet_balance |
| 12 | + |
| 13 | + def update_balance(self, amount): |
| 14 | + if amount < 1000 and amount > 0: |
| 15 | + self.__wallet_balance += amount |
| 16 | + |
| 17 | + def show_balance(self): |
| 18 | + print ("The balance is ",self.__wallet_balance) |
| 19 | + |
| 20 | +c1=Customer(100, "Gopal", 24, 1000) |
| 21 | +c1._Customer__wallet_balance = 10000000000 |
| 22 | +c1.show_balance() |
0 commit comments