判断字母数字空格

输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。

#!/usr/bin/python
import string
def main():
	s=raw_input("please input the string:")
	letter=0
	space=0
	digit=0
	other=0
	for i in s:
		if i.isalpha():
			letter+=1
		elif i.isspace():
			space+=1
		elif i.isdigit():
			digit+=1
		else:
			other+=1
	print "there are %d letter,%d space,%d digit,%d other"%(letter,space,digit,other)
if __name__=="__main__":
	main()
原文地址:https://www.cnblogs.com/hanfei-1005/p/5708103.html