[Tutor] creating the equivalent of string.strip()

Bob Nienhuis bob.nienhuis at gmail.com
Mon Oct 1 01:05:48 CEST 2007


BTW, GMail brings up some interesting sponsored links when the subject line
has string.strip in it ( :-0)

On 9/30/07, Alan Gauld <alan.gauld at btinternet.com> wrote:
>
>
> "wesley chun" <wescpy at gmail.com> wrote in message
> news:78b3a9580709300102x12cbe392uebb988ed965c7202 at mail.gmail.com...
> >> > I'm not sure how to proceed.  My biggest stumbling
> >> > block is how to detect the leading and trailing
> >> > whitespace.
> >>
> >> Use indexing.
> >> Try using a while loop.
> >> Or maybe two?
> >>
> >> And strings have an isspace method...
> >
> > unfortunately, the isspace() string method only returns True if all
> > chars in the string are whitespace chars and False otherwise, so
> > that's a bummer.
>
> But the string can be one character long:
>
> s = 'fred\n'
> print s[-1].isspace()      # --> True
>
> :-)
>
> Alan G
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070930/c8a1d7ee/attachment-0001.htm 


More information about the Tutor mailing list