【发布时间】:2020-06-13 22:15:25
【问题描述】:
这是我尝试从 li 列表中的“two”字符串中获取“t”字符并将其与单个“t”字符进行比较的代码:
li=["one","two","three"];
choice=1;
if li[choice[1]]=="t":
print("valid");
else:
print("unvalid");
问题是当我运行它时,它说:
Traceback (most recent call last):
File "C:\Users\Yobob\Documents\cours\ISN\ProjetISN\testPython.py", line 3, in <module>
if li[choice[1]]=="t":
TypeError: 'int' object is not subscriptable
【问题讨论】: