2020-12-23
阅读量:
3140
python报错: TypeError: unsupported operand type(s) for +=: 'int' and 'list'
问:
python报错:
TypeError: unsupported operand type(s) for +=: 'int' and 'list'

答:
这是因为sum3([6,1,2,3])这种写法是把[6,1,2,3]整体当成一个参数传入函数中,当调用该函数时执行sum0+=i,
由于sum0是“int”,i是“list”,“int”和“list”不能进行“+=”运算会引起报错,
解决方法是将sum3([6,1,2,3])修改为sum3(6,1,2,3)

50.6346
1
0
关注作者
收藏
评论(0)
发表评论
暂无数据
推荐帖子
0条评论
0条评论
0条评论

