如何将索引转换为整数?

时间:2019-02-12 05:50:36

标签: python

第一个打印结果我设法找到字符“ t”的索引。我正在尝试使用结果索引插入到猜测位置,因此我可以替换char的星号。但是在这种情况下,我收到了错误。

word = "python"
store = []
guess = ['*'] * len(word)
for index, char in enumerate(word):
    if char == 't':
        store.append(index)
        print("the index of i is: ", store)

        print(char)

        guess[store] = char
        print(''.join(guess))

1 个答案:

答案 0 :(得分:0)

您需要这样的东西:

word = "python"
store = []
guess = ['*'] * len(word)
for index, char in enumerate(word):
    if char == 't':
        store.append(index)
        print("the index of '%s' is: %s"%(char, index))

        print(char)

        guess[index] = char #guess is list and index is integer here
        print(''.join(guess))