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

Alan Gauld alan.gauld at btinternet.com
Sat Sep 29 09:58:55 CEST 2007

"Christopher Spears" <cspears2002 at yahoo.com> wrote 

> I'm not sure how to proceed.  My biggest stumbling
> block is how to detect the leading and trailing
> whitespace.  

Use indexing.
Recall str[-1] is the last character
str[0] is the first...

Try using a while loop. 
Or maybe two?

And strings have an isspace method...


Alan Gauld
Author of the Learn to Program web site

More information about the Tutor mailing list