On Wed, Feb 3, 2010 at 8:19 AM, NISA BALAKRISHNAN
<snisa.balakrish...@gmail.com> 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

str.split() is the thing to use. By default it splits on any white space:

In [1]: s = "123B     new Project"

In [2]: s.split()
Out[2]: ['123B', 'new', 'Project']

You can tell it to only split once (the None argument means "split on
white space"):
In [5]: s.split(None, 1)
Out[5]: ['123B', 'new Project']

The result is a list; you can assign each element to a variable:
In [6]: first, second = s.split(None, 1)

In [7]: first
Out[7]: '123B'

In [8]: second
Out[8]: 'new Project'

Kent
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to