[Tutor] creating the equivalent of string.strip()
Alan Gauld
alan.gauld at btinternet.com
Sun Sep 30 17:02:34 CEST 2007
"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
More information about the Tutor
mailing list