String Indices must be Integers

I received this error message when I ran the “evaluate_test_cases(count_rotations_generic, test)” cell after completing the code for optional assignment1.
Does anyone know how we can resolve this ?


Already been answered. You’re probably the fourth person I’m responding with the same answer.

3 Likes

All the characters of a string have a unique index . This index specifies the position of each character of the string. TypeError: string indices must be integers means an attempt to access a location within a string using an index that is not an integer.

For example, str[hello"] and str[2.1] as indexes. As these are not integers, a TypeError exception is raised. This means that when you’re accessing an iterable object like a string or float value, you must do it using an integer value .

Python supports slice notation for any sequential data type like lists, strings , tuples, bytes, bytearrays, and ranges. When working with strings and slice notation, it can happen that a TypeError: string indices must be integers is raised, pointing out that the indices must be integers, even if they obviously are.