Today I am going to explain the concept that I was confused with at the beginning(While learning python).
Well, the topic is list slicing.To me, this notation needs a bit of picking up. It looks extremely powerful,
but I haven't quite got my head round it and am looking for a good guide.This post will be a simple short explaination of this
concept.
Generally, List slicing can be easily understood except for negative index accessing.So, let me explain this concept by naming the indices as
start and end and the skipping number as step.My explaination will be similar to the implementation of range method in python.
a[start:end] # items start through end-1
a[start:] # items start through the rest of the array
a[:end] # items from the beginning through end-1
a[:] # a copy of the whole array
a[start:end:step] # start through not past end, by step
a[-1] # last item in the array
a[-2:] # last two items in the array
a[:-2] # everything except the last two items
Written by Vivek Soundrapandi
Published Date: {{ article.pub_date }}
View all posts by: Vivek Soundrapandi