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编程python时报错

错误如下:
TypeError: slice indices must be integers or None or have an __index__ method_第1张图片

解决方法:

只需要用int()对索引 len(s) / 2等进行强制类型转换,如下
TypeError: slice indices must be integers or None or have an __index__ method_第2张图片

这样就OK啦!

你可能感兴趣的:(python)