String slices work only for first string character ?

Barak, Ron Ron.Barak at lsi.com
Wed Dec 17 02:43:16 EST 2008


Thanks to all who pointed my wrong understanding of how string slices are defined.
Bye,
Ron.

________________________________
From: Barak, Ron [mailto:Ron.Barak at lsi.com]
Sent: Tuesday, December 16, 2008 15:35
To: python-list at python.org
Subject: String slices work only for first string character ?


Hi,

Can any one explain why the following string slice works only for the first character, but not for any other ?

$ cat /tmp/tmp.py
#!/usr/bin/env python

data = 'F0023209006-0101'
print data
print "|"+data[0:1]+"|"
print "|"+data[1:1]+"|"
print "|"+data[2:1]+"|"

$ python `cygpath -w /tmp/tmp.py`
F0023209006-0101
|F|
||
||

$

Thanks,
Ron.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20081217/2e6faf0d/attachment-0001.html>


More information about the Python-list mailing list