语法错误

时间:2019-08-18 15:21:37

标签: python-3.x class

我正在使用一种方法向我返回押金的值,但是它显示语法错误。

class Account:
    def __init__(self,owner,balance):
        self.owner= owner
        self.balance= balance

    def deposit(self,amount_in):
         return self.balance+=amount_in
    def withdraw(self,amount_out):
        if amount_out>self.balance:
            print("Ther is not enough balance in your account")
        else:
            self.balance= self.balance- amount_out
    def __str__(self):
        return str(self.owner) + ' ' + str(self.balance)

错误:

 File "<ipython-input-101-7e8824d5cebe>", line 7
    return self.balance+=amount_in
                        ^
SyntaxError: invalid syntax

1 个答案:

答案 0 :(得分:1)

您正在尝试退回作业。

只需将您的代码更改为此:

def deposit(self,amount_in):
    self.balance+=amount_in