class User:
def __init__(self, name, age, email):
self.name = name
self.age = age
self.email = email
def greeting(self):
return f'My name is {self.name} and I am {self.age}'
# heritage User class
class Customer(User):
def __init__(self, name, age, email):
self.name = name
self.age = age
self.email = email
self.balance = 0
def set_balance(self, balance):
self.balance = balance
def greeting(self):
return f'My name is {self.name} and I am {self.age} and I owe a balance of {self.balance}'
# Init user object
mia = User('Mia Luo', 23, 'mia@gmail.com')
# call method
mia.age = 33
print(mia.greeting())
# Init customer
john = Customer('John Doe', 22, 'johndoe@gmail.com')
# call method
john.set_balance(30000)
print(john.greeting())
03-26
480
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
11-21
3480
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
11-11