Python Tutorial - 4 - Slicing up Strings

+1 WEN JIE TAY · March 3, 2015
Hey Guys , i have understand issue regarding the tutorial for this code as follows :

>>> title="Little Apple"
>>> title[0:5]

'Littl'

Why am i not getting 'Little' ??

as from my understanding now 'L' is in the index 0 & 'e' is in index 5

Thanks for Taking time reading

Post a Reply

Replies

Oldest  Newest  Rating
0 Ricky singh · March 3, 2015
hey

title = "Little Apple"

first = title[0:] => this will print the whole title ("Little Apple")

second = title[0,6] => this will print the word "Little"
(in the second example it will start slicing from the first given argument which is 0 and continue till the second given argument-1)

third = title[:6] => this will print the word " Apple"

i hope i was able to clear the doubt
  • 1

Python

107,234 followers
About

This section is all about snakes! Just kidding.

Links
Moderators
Bucky Roberts Administrator