【发布时间】:2020-01-29 10:22:33
【问题描述】:
我正在阅读 Python 教程,但不知道为什么我的代码不起作用。我知道我需要告诉 Python 手动打印一个整数,但我已经输入了str(sum(ages))。谁能告诉我为什么会这样?
ages = ['24','34','51','36','57','21','28']
print('The oldest in the group is ' + str(max(ages)) + '.')
print('The youngest in the group is ' + str(min(ages)) + '.')
print('The combined age of all in the list is ' + str(sum(ages)) + '.')
错误:
File "list2.py", line 4, in <module>
print('The combined age of all in the list is ' + str(sum(ages)) + '.')
TypeError: unsupported operand type(s) for +: 'int' and 'str'
【问题讨论】:
标签: python python-3.x string list sum