Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   RE: Isn't there a substring(start, end)-function???? (http://www.velocityreviews.com/forums/t320638-re-isnt-there-a-substring-start-end-function.html)

Harvey Thomas 08-06-2003 01:37 PM

RE: Isn't there a substring(start, end)-function????
 
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!
>
> Dave


There isn't a substring function, because it's not necessary as slices do the job.
The short answer is:

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

but its explained much more fully in
http://www.python.org/doc/current/tu...00000000000000

Harvey

__________________________________________________ ___________________
This message has been checked for all known viruses by the MessageLabs Virus Scanning Service.



All times are GMT. The time now is 12:30 AM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57