小编use*_*979的帖子

添加我的班级的两个实例

我想添加到我的类的实例中Bar:

x = Bar([5, 12, 5])
y = Bar([4, 5, 6])
x+y #Bar([9, 17, 11])
Run Code Online (Sandbox Code Playgroud)

这是班级:

class Bar:
    def __init__(self, arr):
        self.items = arr
    def __repr__(self):
        return "Bar("+str(self.items)+")"
Run Code Online (Sandbox Code Playgroud)

python oop class add instance

2
推荐指数
1
解决办法
2917
查看次数

标签 统计

add ×1

class ×1

instance ×1

oop ×1

python ×1