|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
def count(*par):
length = len(par)
for i in range(length):
letters = 0
sapce = 0
digit = 0
others = 0
for each in par[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 love fishc.com.','I love you , you love me.')
他说 space += 1 那里 local variable 'space' referenced before assignment ,赋值前引用了局部变量'space' |
|