Python中的TypeError“int”

2024-04-25 10:11:05 发布

您现在位置:Python中文网/ 问答频道 /正文

randsemiconclusion = [3234234, 234234, 23432]
wordstring = "                                                  "
liststr = list(wordstring)
for i in range(0, len(randsemiconclusion)):
    aw = randsemiconclusion[i]
    for j in range(0, 6):
        aac = int(i*7 + j+1)
        liststr[aac] = aw[j]
        wordstring = ''.join(liststr)
print("Wordstring -->  ", wordstring, "  <--")

回溯:

Traceback (most recent call last):

liststr[aac] = aw[j]

TypeError: 'int' object is not subscriptable

(这只是一个提取器-真正的代码)

我不知道为什么我会得到TypeError

此程序应提取列表中的数字,并将它们放在一个字符串中,如下所示:

list[12, 23, 32]

to:

122332


Tags: inforlenrangelistintprintjoin
1条回答
网友
1楼 · 发布于 2024-04-25 10:11:05

您可以重写如下函数:

def concatenate_list_data(list):
    result= ''
    for element in list:
        result += str(element)
    return result

my_result = concatenate_list_data([1, 5, 12, 2])   # leads to 15122

相关问题 更多 >