一个挺简单的python编程,看看谁写的更python,
本帖最后由 Cria 于 2020-4-12 21:10 编辑编写函数,接收一个字符串,分别统计大写字母、小写字母、数字、其它字符的个数,并以元组的形式返回结果,最后调用测试。(看看有没有用推导式的大佬)
小生不才,参考一个
intCount = []
upstrCount = []
lowstrCount = []
otherCount = []
def text(a):
for i in a:
if i.isdigit():
intCount.append(i)
elif i.islower():
lowstrCount.append(i)
elif i.isupper():
upstrCount.append(i)
else:
otherCount.append(i)
return intCount,upstrCount,lowstrCount,otherCount
a = input('请输入一个字符串:')
a,b,c,d = text(a)
print('数字的个数:{}'.format(len(a))+ ',' +'大写字母的个数:{}'.format(len(b)) + ',' + '小写字母的个数:{}'.format(len(c)) + ',' + '其他字符的个数:{}'.format(len(d)))
a=tuple(a)
b=tuple(b)
c=tuple(c)
d=tuple(d)
print(a,b,c,d)
本帖最后由 zltzlt 于 2020-4-12 21:13 编辑
def func(s):
return sum(map(str.isupper, s)), sum(map(str.islower, s)), sum(map(str.isdigit, s)), sum(map(lambda x: not x.isalnum(), s)) 感觉楼主被完败{:5_111:} {:9_227:} zltzlt 发表于 2020-4-12 20:59
就是要写出让小白很震惊也看不懂的代码{:10_256:} z13970027151 发表于 2020-4-13 11:18
感觉楼主被完败
讲真的,我傻了 Cria 发表于 2020-4-13 12:37
讲真的,我傻了
我亦无他,唯手熟尔{:10_256:}
@zltzlt
页:
[1]