Python str_i+=e[0]+“\t”+e[1]+“\n”

Python str_i+=e[0]+“\t”+e[1]+“\n”,python,Python,我正在尝试打印堆栈,但我得到了以下结果: str_i += e[0] + "\t" + e[1] + "\n" TypeError: unsupported operand type(s) for +: 'int' and 'str' 如何让堆栈打印 def __str__(self): str_i = 0 for e in self.items: str_i += e[0] + "\t" + e[1] + "\n" return str_i

我正在尝试打印堆栈,但我得到了以下结果:

str_i += e[0] + "\t" + e[1] + "\n"
TypeError: unsupported operand type(s) for +: 'int' and 'str'
如何让堆栈打印

def __str__(self):
    str_i = 0
    for e in self.items:
        str_i += e[0] + "\t" + e[1] + "\n"
    return str_i       

s1 = Stack_2Queues()
s1.push(903, 12)
s1.push(767, 13)
s1.push(950, 14)
print(s1)
尝试使用以下方法:

str_i = ''
for e in self.items:
    str_i += "{}\t{}\n".format(e[0],e[1])

执行此操作时定义str_i:str_i=0不应该是str_i=?…然后str_i+=stre[0]+\t+stre[1]+\n阅读并思考错误消息的内容。您正在尝试连接字符串和整数。您将如何解决此问题?