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

Eric Brunel eric.brunel at pragmadev.com
Wed Aug 6 08:08:22 EDT 2003


Dave wrote:
> 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!

You are ;-) You couldn't find it in the documentation for the modules because 
it's a base operator on the string itself:

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

See: http://www.python.org/doc/current/lib/typesseq.html

HTH
-- 
- Eric Brunel <eric.brunel at pragmadev.com> -
PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com





More information about the Python-list mailing list