+2 votes
2 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 (46.1k 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 (107k 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:-

           

Related questions

0 votes
1 answer
asked Jul 24, 2019 in Python by Eresh Kumar (30.2k points)
+1 vote
2 answers
0 votes
2 answers
asked May 30, 2019 in Python by Anvi (10.2k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...