String Problem, What is it I don't understand?
Manuel M. Garcia
mgarcia at cole-switches.com
Thu Jan 16 17:41:46 EST 2003
On Thu, 16 Jan 2003 18:58:29 GMT, Bubba <bub at joos.us> wrote:
(edit)
>I would expect to get the month day and year from the following, but
>day and year are null
>xxx = "01/17/03"
>month = xxx[0:2]
>print "month=",month
>day = xxx[3:2]
>print "day=",day
>year = xxx[6:2]
>print "year=",year
(Please use Fixed Pitch Font)
+---------------------------------------------------+
| Python indexes and slices for a six-element list. |
| Indexes enumerate the elements |
| Slices enumerate the spaces between the elements. |
| |
| Index from rear: -6 -5 -4 -3 -2 -1 |
| Index from front: 0 1 2 3 4 5 |
| +---+---+---+---+---+---+ |
| | a | b | c | d | e | f | |
| +---+---+---+---+---+---+ |
| Slice from front: : 1 2 3 4 5 : |
| Slice from rear: : -5 -4 -3 -2 -1 : |
| |
| a=[0,1,2,3,4,5] a[1:]==[1,2,3,4,5] |
| len(a)==6 a[:5]==[0,1,2,3,4] |
| a[0]==0 a[:-2]==[0,1,2,3] |
| a[5]==5 a[1:2]==[1] |
| a[-1]==5 a[1:-1]==[1,2,3,4] |
| a[-2]==4 |
| |
| b=a[:] |
| b==[0,1,2,3,4,5] (shallow copy of a) |
+---------------------------------------------------+
Manuel
More information about the Python-list
mailing list