Understanding Python s slice notation

0 votes
I need a good explanation on Python's slice notation.

To me, this notation needs a bit of picking up.

It looks extremely powerful, but I haven't quite got my head around it.
Oct 25, 2018 in Python by ana1504.k
• 7,910 points
330 views

1 answer to this question.

0 votes
It's pretty simple really:

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
There is also the step value, which can be used with any of the above:

a[start:end:step] # start through not past end, by step
The key point to remember is that the :end value represents the first value that is not in the selected slice. So, the difference beween end and start is the number of elements selected.
answered Oct 25, 2018 by SDeb
• 13,300 points

Related Questions In Python

0 votes
1 answer

Understanding slice notation

To answer your question let me explain ...READ MORE

answered Feb 4 in Python by Nandini
• 5,480 points
51 views
0 votes
1 answer

Slice notation in Python for string reversal

The slice notation is [start:end:step]. Step = ...READ MORE

answered Apr 25, 2018 in Python by Nietzsche's daemon
• 4,260 points
288 views
+4 votes
8 answers

How can I use Python's range function?

The range function is mostly used in for-loop.  Ex: for ...READ MORE

answered Aug 21, 2018 in Python by Omkar
• 69,210 points
545 views
0 votes
1 answer
0 votes
1 answer

How does slice notation in Python work?

The Python tutorial talks about it (scroll down a ...READ MORE

answered Oct 31, 2018 in Python by Priyaj
• 58,080 points
216 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 2,907 views
0 votes
1 answer

Does Python's time.time() return the local or UTC timestamp?

The time.time() function returns the number of seconds since ...READ MORE

answered Oct 5, 2018 in Python by SDeb
• 13,300 points
346 views
0 votes
1 answer

Understanding generators in Python

A generator is simply a function which ...READ MORE

answered Oct 26, 2018 in Python by SDeb
• 13,300 points
214 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP