Q. An index out of bounds given with a list name causes error, but not with list slices. Why?


Answer =

Because Slices are treated as boundaries instead, and the result will simply contain all items between the boundaries. For the start and stop given beyond list limits in a list slice (i.e., out of bounds), Python simply returns the elements that fall between specified boundaries, if any, without raising any error.

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post