Isn't there a substring(start, end)-function????
Irmen de Jong
irmen at -NOSPAM-REMOVETHIS-xs4all.nl
Wed Aug 6 14:23:58 CEST 2003
> Am I blind, or what? I can't find any quick way to do the following in
> substring(beginIndex, endIndex) witch returns the substring between
> beginIndex and endIndex.
> text = "If someone attacks you with a banana"
> print text.substring(0,3)
> Should print "If "
You're not blind but you've overlooked string slicing:
Python 2.3 (#46, Jul 29 2003, 18:54:32) [MSC v.1200 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> text = "If someone attacks you with a banana"
>>> print text[0:3]
>>> print text[3:10]
>>> print text[-6:]
>>> print text[::-1]
ananab a htiw uoy skcatta enoemos fI
more info here: http://www.python.org/doc/current/ref/slicings.html
More information about the Python-list