[Tutor] how to strip whitespaces from a string.
kumar s
ps_python at yahoo.com
Fri Oct 8 19:24:47 CEST 2004
Thank you.
But I messed up my question.
s = " I am learning python "
f = s.strip()
f
'I am learning python'
How can I get the ouput to:
'Iamlearningpython'.
That mean how can i remove whitespaces between words
in a line and join all the words.
sorry for asking twisted question.
Thank you.
kumar
--- Calum Mackay <calum.mackay at cdmnet.org> wrote:
> kumar s wrote:
> > Dear group,
> > I have been practising python for some time now
> and
> > string method 'strip' always remains an alien to
> me.
> > whenever i try to use it, i never got what i want
> and
> > now it still remainins an enigma.
> >
> > s = " I am learning python"
> >
> > how can i remove white spaces from 's'.
> >
> > f = s.strip('\w') - wrong
>
> Do you want to strip trailing and leading ws only?
> If so, then you just
> want:
>
> f = s.strip()
>
> since that's what strip() does by default.
>
> cheers,
> c.
>
_______________________________
Do you Yahoo!?
Declare Yourself - Register online to vote today!
http://vote.yahoo.com
More information about the Tutor
mailing list