【发布时间】:2021-07-24 14:42:29
【问题描述】:
我正在学习 python,而我正在做这个练习......
student_scores = input("Input a list of student scores here ")
for n in range(0, len(student_scores)):
student_scores[n] = int(student_scores[n])
print(student_scores)
highest_score = max(student_scores)
print(highest_score)
**i got the below error:**
line 5, in <module>
student_scores[n] = int(student_scores[n])
TypeError: 'str' object does not support item assignment
【问题讨论】:
-
嗯,你希望发生什么而不是?您正在尝试分配 number 来代替 immutable 字符串中的 character。
-
用你自己的话来说:当代码
student_scores[n] = int(student_scores[n])运行时,你认为应该发生什么?显示一个示例,说明您对student_scores之前和之后的期望。我什至无法猜测您希望整个代码做什么。请阅读How to Ask 并提出实际问题。告诉我们您要解决什么问题,并附上一个以?结尾的问题。 -
友好一点吧,伙计们!关于 python 的一些事情让学习者感到惊讶,比如字符串是不可变的(在许多语言中并非如此)。
标签: python python-3.x string object oop