[Tutor] how to strip whitespaces from a string.
ps_python at yahoo.com
Fri Oct 8 19:24:47 CEST 2004
But I messed up my question.
s = " I am learning python "
f = s.strip()
'I am learning python'
How can I get the ouput to:
That mean how can i remove whitespaces between words
in a line and join all the words.
sorry for asking twisted question.
--- Calum Mackay <calum.mackay at cdmnet.org> wrote:
> kumar s wrote:
> > Dear group,
> > I have been practising python for some time now
> > string method 'strip' always remains an alien to
> > whenever i try to use it, i never got what i want
> > 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
> f = s.strip()
> since that's what strip() does by default.
Do you Yahoo!?
Declare Yourself - Register online to vote today!
More information about the Tutor