|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
def count(*param):
cc = len(param)
for i in range(cc):
letters = 0
space = 0
digit = 0
others = 0
for each in param[i]:
if each.isalpha():
letters += 1
elif each.isdigit():
digit += 1
elif each == ' ':
space += 1
else:
others += 1
print('第%d个字符串共有:英文字母%d个,数字%d个,空格%d个,其他字符%d个。' % (i+1, letters, digit, space, others))
count('I 3v2e you .','Thanks you ')
为什么程序不查第一个参数。。。我换了好多地方,程序正常但就是不查第一个参数
- def splitTuple(*param):
- #print(param) #('I 3v2e you .', 'Thanks you ')
- for i,cc in enumerate(param):
- count(i,cc)
- #print(cc)
- def count(n, cc):
- for i in range(len(cc)):
- letters = 0
- space = 0
- digit = 0
- others = 0
- for each in cc:
- if each.isalpha():
- letters += 1
- elif each.isdigit():
- digit += 1
- elif each == ' ':
- space += 1
- else:
- others += 1
- print('第%d个字符串共有:英文字母%d个,数字%d个,空格%d个,其他字符%d个。' % (n, letters, digit, space, others))
-
- splitTuple('I 3v2e you .','Thanks you ')
复制代码
---
- >>>
- 第0个字符串共有:英文字母6个,数字2个,空格3个,其他字符1个。
- 第1个字符串共有:英文字母9个,数字0个,空格2个,其他字符0个。
- >>>
复制代码
|
|