美文网首页
TypeError: slice indices must be

TypeError: slice indices must be

作者: singed | 来源:发表于2018-08-30 13:00 被阅读0次
nums = [1, 4, 3, 2]
print(nums[0:len(nums)/2])

    print(nums[0:len(nums)/2])
TypeError: slice indices must be integers or None or have an __index__ method

print(len(nums)/2) 发现是浮点数(刚换的Python3)

把/改为//取整就正常了

nums = [1, 4, 3, 2]

print(nums[0:len(nums)//2])

相关文章

网友评论

      本文标题:TypeError: slice indices must be

      本文链接:https://www.haomeiwen.com/subject/cavrwftx.html