Slicing a list
Title
Question
week_name=["mon","tue","wed","thu","fri","sat","sun"]
why does week_name[-1:-5] returns [ ]
Python-3.4.3 Manipulating-lists 01-02 min 50-60 sec
Answers:
The pointer that traverses the list when slicing or striding only moves from left to right, so when you say week_name[-1:-5], the interpreter tries to start from -1 (sun) and move towards the right to fetch more elements, however there are no more elements to the right of -1 hence it returns an empty list
Login to add comment