成功解决TypeError: slice indices must be integers or None or have an __index__ method

简介: 成功解决TypeError: slice indices must be integers or None or have an __index__ method

解决问题


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




解决思路


类型错误:切片索引必须是整数或无,或者有一个__index__ 的方法




解决方法


对要切分的数值,进行整数转换

比如,

num

改为

int(num)


哈哈,大功告成!


相关文章
|
3天前
|
Python
完美解决丨2. `TypeError: list indices must be integers or slices, not str`
完美解决丨2. `TypeError: list indices must be integers or slices, not str`
|
Python
解决only integer scalar arrays can be converted to a scalar index
解决only integer scalar arrays can be converted to a scalar index
310 0
解决only integer scalar arrays can be converted to a scalar index
|
Python
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or
408 0
TypeError: tuple indices must be integers, not tuple是怎么回事
TypeError: tuple indices must be integers, not tuple是怎么回事
214 0
TypeError: cannot concatenate ‘str‘ and ‘list‘ objects
TypeError: cannot concatenate ‘str‘ and ‘list‘ objects
|
Linux Python
ValueError: empty range for randrange() (0, 0, 0)
ValueError: empty range for randrange() (0, 0, 0)
成功解决ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or
成功解决ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or
|
索引 Python
成功解决ValueError: Shape of passed values is (33, 1), indices imply (33, 2)
成功解决ValueError: Shape of passed values is (33, 1), indices imply (33, 2)