Isn't there a substring(start, end)-function????

Michael Hudson mwh at python.net
Wed Aug 6 14:00:19 CEST 2003


davidhe at email.com (Dave) writes:

> Hi all,
> 
> Am I blind, or what? I can't find any quick way to do the following in
> Python:
> 
> substring(beginIndex, endIndex) witch returns the substring between
> beginIndex and endIndex.
> 
> Like:
> text = "If someone attacks you with a banana"
> print text.substring(0,3)
> Should print "If "
> 
> I've found absolutely everything else that I expect from a modern
> programming language, but none of the modules (not even "string"!)
> seems to have what I'm looking for.
> 
> Please tell me I'm blind!

Well, you're just not looking in the right place:

>>> text = "If someone attacks you with a banana"
>>> text[0:3]
'If '

I'm pretty sure this is in the tutorial -- the key word you're looking
for is "slice".

Cheers,
mwh

-- 
  [2. More type system hacking --- text/plain; type-argh.diff]
                                                  -- csr on sbcl-devel




More information about the Python-list mailing list