Why does slice [:-0] return empty list in Python

…衆ロ難τιáo~ 提交于 2019-12-05 04:31:11

-0 is 0, and a slice that goes from the beginning of a list inclusive to index 0 non-inclusive is an empty list.

Python doesn't treat -0 any different from 0.

blah[:0]

means all elements up to but not including the first one. This is an empty list, and blah[:-0] is exactly the same thing.

You can test this by checking that

blah[0:]

is the whole list, starting from the first element.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!