how do I count spaces at the beginning of a string?
Anthony Irwin
nospam at noemailhere.nowhere
Wed May 16 23:10:59 EDT 2007
walterbyrd wrote:
> The strings start with whitespace, and have a '*' or an alphanumeric
> character. I need to know how many whitespace characters exist at the
> beginning of the string.
>
Hi,
I am new to python and just really learning but this is what I came up
with.
#!/usr/bin/env python
def main():
s = " abc def ghi"
count = 0
for i in s:
if i == ' ':
count += 1
else:
break
print count
if __name__ == '__main__':
main()
--
Kind Regards,
Anthony Irwin
http://www.irwinresources.com
http://www.makehomebusiness.com
email: anthony at above domains, - www.
More information about the Python-list
mailing list