统计字符串参数(可能不止一个参数)中的数字、字母、空格和其他字符
# 分别统计字符串参数(可能不止一个参数)中的数字、字母、空格和其他字符def count(*argu):
length = len(argu)
for i in range(length):
number, letter, space, other = 0, 0, 0, 0
for each in argu:
if each.isalpha():
letter += 1
elif each.isdigit():
number += 1
elif each == " ":
space += 1
else:
other += 1
print('第%d个字符串中共有:%d个字母,%d个数字,%d个空格,%d个其他字符' % (i + 1, letter, number, space, other))
count("We love each other deeply!", "I love you, you love me 2.")
页:
[1]