String Problem, What is it I don't understand?

Mike C. Fletcher mcfletch at rogers.com
Thu Jan 16 14:16:28 EST 2003


Slices use absolute indices for both start and stop, not start, length 
indices:

    xxx[3:5] # between positions 3 and 5
and
    xxx[6:8] # between positions 6 and 8
    xxx[6:] # between 6 and end of string
    xxx[:2] # between start-of-string (0) and position 2
    xxx[:-2] # between start-of-string and negative position 2 (2 from end)

while:

    xxx[3:2] # between positions 3 and 2 (nothing)

HTH,
Mike

Bubba wrote:

>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
>
>Python 2.2.2 (#37, Oct 14 2002, 17:02:34) [MSC 32 bit (Intel)] on
>win32
>Type "copyright", "credits" or "license" for more information.
>IDLE 0.8 -- press F1 for help
>  
>
>month= 01
>day= 
>year=
>  
>

-- 
_______________________________________
  Mike C. Fletcher
  Designer, VR Plumber, Coder
  http://members.rogers.com/mcfletch/








More information about the Python-list mailing list