What's correct Python syntax?

Rustom Mody rustompmody at gmail.com
Tue Jan 14 05:51:15 EST 2014


On Tuesday, January 14, 2014 4:05:27 PM UTC+5:30, Igor Korot wrote:
> Hi, Rustom,
> 
> 
> 
> On Tue, Jan 14, 2014 at 2:16 AM, Rustom Mody wrote:
> > You want this?
> >
> >>>> test = "I,like,my,chocolate"
> >>>> test.split(',')
> > ['I', 'like', 'my', 'chocolate']
> >>>> test.split(',')[2:4]
> > ['my', 'chocolate']
> 
> 
> Yup, thats it.
> Now 2 and 4 - it's a starting point and ending point, right?

In python ranges are usually lo-inclusive hi-exclusive.
Slices are one case of this

See explanations:
http://docs.python.org/2/tutorial/introduction.html#strings
and
http://stackoverflow.com/questions/509211/pythons-slice-notation

Neat theoretical explanation
http://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html



More information about the Python-list mailing list