Back

Explore Courses Blog Tutorials Interview Questions
+2 votes
3 views
in Python by (3.5k points)
edited by
I think the slice notation are sort of powerful but I don't know much about it, So can anyone give me a good explanation on Python's slice notation?

2 Answers

0 votes
by (46k points)

It's a very simple thing and well explained from ASCII art diagram for how slices work

 +---+---+---+---+---+---+
 | P | y | t | h | o | n |
 +---+---+---+---+---+---+
 0   1   2   3   4   5   6
-6  -5  -4  -3  -2  -1

think the indices as pointing between characters, see the left edge above as it's pointing at first character numbered 0. Then at the right edge of last character of a string of n characters has index n.

You can look into the Python help section for reference .

Happy Learning, Cheers..!!

0 votes
by (106k points)

It is very simple:

a[start:stop]  

a[start:]      

a[:stop]      

a[:]

You can use the following video tutorials to clear all your doubts:-

Learn in detail about Python by enrolling in Intellipaat Python Course online and upskill.          

Related questions

0 votes
1 answer
asked Jul 24, 2019 in Python by Eresh Kumar (45.3k points)
+1 vote
2 answers
0 votes
2 answers
asked May 30, 2019 in Python by Anvi (10.2k points)

Browse Categories

...