What to do in Python error when trying to access list by index - “List indices must be integers, not str”?

541    Asked by GayatriJaiteley in Python , Asked on Mar 1, 2021
Answered by Gayatri Jaiteley

To get rid of this error you can use the below-mentioned code:-

>>> player=[1,2,3]

>>> player["score"]

Traceback (most recent call last):

 File "", line 1, in

TypeError: list indices must be integers, not str

>>> player={'score':1, 'age': 2, "foo":3}

>>> player['score']



Your Answer

Interviews

Parent Categories