def check(count):
lowercase = 0
uppercase = 0
other = 0
low = 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'
upper = 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'
for n in count:
if n in low:
lowercase += 1
elif n in upper:
uppercase += 1
else:
other += 1
print("There are " + str(lowercase) + " lowercase letters.")
print("There are " + str(uppercase) + " uppercase letters.")
print("There are " + str(other) + " other elements to this sentence.")
如果字符串中的所有字符都是字母,并且至少有一个字符,则返回true,否则返回false。字母字符是Unicode字符数据库中定义为“字母”的字符,即具有“Lm”、“Lt”、“Lu”、“Ll”或“Lo”中的“general category”属性的字符。请注意,这与Unicode标准中定义的“字母”属性不同。
在python2.x中:
在python3.x中:
此代码有效:
您可以使用^{} 。
例如:
输出:
我找到了一个使用函数和基本代码的好方法。 这是一个代码,它接受一个字符串,并计算大写字母、小写字母和“其他”的数量。另一种被归类为空格、标点符号,甚至是日文和中文。
相关问题 更多 >
编程相关推荐