下面是我尝试从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