Python面向对象程序设计:设计一个account类,完成deposite和witPython面向对象程序设计:设计一个account类hdraw实例函数 并生成对象

Python面向对象程序设计:设计一个account类,完成deposite和withdraw实例函数,并生成对象

>>> class account:
    def __init__(self,money = 100):
        self.money = money
    def deposite(self):
        self.money = 1000
    def withdraw(self):
        self.money = 0

        
>>> Account = account()
>>> Account.money
100
>>> Account.deposite()
>>> Account.money
1000
>>> Account.withdraw()
>>> Account.money
0
class Account():
    def __init__(self, money=0):
        self.money = money
    def deposite(self, amount):
        self.money += amount
    def withdraw(self, amount):
        self.money -= amount
        if self.money < 0:
            print('余额不足,已全部取出')
            self.money = 0