String slices work only for first string character ?
Ron.Barak at lsi.com
Tue Dec 16 14:51:10 CET 2008
Hi Mr. Cain,
Mae culpa: obviously, I erroneously understood the number after the ':' as the string length.
From: D'Arcy J.M. Cain [mailto:darcy at druid.net]
Sent: Tuesday, December 16, 2008 15:45
To: Barak, Ron
Cc: python-list at python.org
Subject: Re: String slices work only for first string character ?
On Tue, 16 Dec 2008 13:35:27 +0000
"Barak, Ron" <Ron.Barak at lsi.com> wrote:
> Can any one explain why the following string slice works only for the first character, but not for any other ?
I think that you need to reread the docs on slices.
> print "|"+data[0:1]+"|"
> print "|"+data[1:1]+"|"
If you want the second character use "data[1:2]".
D'Arcy J.M. Cain <darcy at druid.net> | Democracy is three wolves
http://www.druid.net/darcy/ | and a sheep voting on
+1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner.
More information about the Python-list