[Python] "TypeError: list indices must be integers" when iterating over a list

Discussão em 'Python' iniciado por Stack, Agosto 6, 2025.

  1. Stack

    Stack Membro Participativo

    I would like to do something like this:

    stuff = ['Foo', 'Bar']

    someString = ''
    for i in stuff:
    someString += stuff

    print(someString)
    # -> FooBar


    But I get an error from the line containing stuff:


    TypeError: list indices must be integers, not str
    ​

    I tried to change it to string like this:

    someString += str(stuff)


    but still get the same error.

    Continue reading...

Compartilhe esta Página