0
List slicing in python
#list slicing Friends=["harry","tom","rohan","sam","divya","45"] Print(friends [0:4])
6 Answers
+ 3
Yes, you can also give negative values for indices. The negative indexing starts from where the list ends. It means that the index value of -1 gives the last element, and -2 gives the second last element of a list.
[-2:-4 ] here, slicing starts from second last element and ends with 4th element from the backwards. It returns [] because, there is no element between these two with the step of 1.
You can try this and see the output.
[-2:-4:-1] it goes backwards since step value is -1.
We already discussed about list slicing a few months ago.
Hope it helps you
https://www.sololearn.com/discuss/2955122/?ref=app
+ 2
Yeah, it returns the elements from 0 to 4 without including 4th element of the friends list.
You have any questions than this?
0
???
0
Yes i am in doubt...
0
Actually I can't understand
#list slicing
Friends=["harry","tom","rohan","sam","divya","45"]
Print(friends [-2 : -4])
Can I write in this way
Or the output what's comes
0
???