|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
def count(*param):
length = len(param)
for i in range(length):
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 love fishc.com.', 'I love you, you love me.')
如果我想查询isalpha和isdigit这两个函数里面的内容和说明,需要在idle通过什么方式查询???
- >>> help(str.isalpha)
- Help on method_descriptor:
- isalpha(self, /)
- Return True if the string is an alphabetic string, False otherwise.
-
- A string is alphabetic if all characters in the string are alphabetic and there
- is at least one character in the string.
- >>> help(str.isdigit)
- Help on method_descriptor:
- isdigit(self, /)
- Return True if the string is a digit string, False otherwise.
-
- A string is a digit string if all characters in the string are digits and there
- is at least one character in the string.
复制代码
|
|