[Tutor] help with strings

Darren Worrall dw at darrenworrall.co.uk
Wed Feb 3 16:10:59 CET 2010


On 03/02/10 13:19, NISA BALAKRISHNAN wrote:
> hi
>
> I am very new to python.
> I have a string for example : 123B     new Project
> i want to separate 123B as a single string and new  project as another 
> string .
> how can i do that.
> i tried using partition but couldnt do it
>
> pls help.
> thanks in advance!
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>    
Assuming the whitespace isn't relevant, and is just a delimiter:

 >>> s = '123B     new Project'
 >>> s.split(None, 1)
['123B', 'new Project']

The first argument to split() is the delimiter (or if None, it defaults 
to whitespace), and the second argument is 'maxsplit' - the amount of 
splits to make. It's explained well in the documentation[1].

Cheers,

Daz

[1]http://docs.python.org/library/stdtypes.html#str.split
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100203/e30835ba/attachment.htm>


More information about the Tutor mailing list