6.0k views
0 votes
Slice indices must be integers or none or have an __index__ method

1 Answer

4 votes

Answer:

This is an error (TypeError) that is displayed by the Python interpreter when one of the parameter in a slice function is not a value of type integer or None.

For example:

>>> a = 'welcome'

>>> a[2.2:3]

Traceback (most recent call last):

File "<stdin>", line 1, in <module>

TypeError: slice indices must be integers or None or have an __index__ method

The error occur because the value 2.2 is not an integer or None

Explanation:

User Jimav
by
4.4k points