小编Rit*_*h B的帖子

简单类属性更新

我有一个课我期待这个:

print(rithesh.amount) = 150.
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?

这是我的代码:

class Customer:

    total_amount = 0

    def __init__(self, name, mob, email, amount=None):
        self.name = name
        self.mob = mob
        self.eamil = email

    def add_amount(self, amount):
        self.amount = amount

rithesh = Customer("Rithesh", "8896398598", "ritheshb1@gmail.com")
rithesh.add_amount(100)
rithesh.add_amount(50)
print(rithesh.amount)
Run Code Online (Sandbox Code Playgroud)

python oop class

0
推荐指数
1
解决办法
43
查看次数

标签 统计

class ×1

oop ×1

python ×1