How do I count the number of spaces at the left end of a string?

James Stroud jstroud at mbi.ucla.edu
Wed May 16 18:06:32 EDT 2007


walterbyrd wrote:
> I don't know exactly what the first non-space character is. I know the
> first non-space character will be  * or an alphanumeric character.
> 

This is another of the hundreds of ways:

py> for i,c in enumerate(astring):
...   if c != ' ': break
...
py> print i



More information about the Python-list mailing list