[Tutor] how to strip whitespaces from a string.
Calum Mackay
calum.mackay at cdmnet.org
Fri Oct 8 19:20:02 CEST 2004
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.
More information about the Tutor
mailing list