我一直试图创建一个创建程序,该程序在变量中找到第n个数字,在这种情况下为0000。尽管如此,我总是遇到错误。
我知道我必须将列表中得到的数字转换为字符串,所以我做到了。收到错误后,我尝试将其保留为整型,但仍然无法正常工作。
seenatalllist = [0000]
orglastcodevalue = seenatalllist[-1]
print(orglastcodevalue)
lastcodevalue = str(orglastcodevalue)
lastcodevalue1 = (lastcodevalue[0])
print(lastcodevalue1)
lastcodevalue2 = (lastcodevalue[1])
print(lastcodevalue2)
lastcodevalue3 = (lastcodevalue[2])
print(lastcodevalue3
lastcodevalue4 = (lastcodevalue[3])
print(lastcodevalue4)
我希望它能打印:
0
0
0
0
相反,我对于lastcodevalue2 =(lastcodevalue [1])遇到此错误:
IndexError:字符串索引超出范围