统计字符串字符个数,空格字符个数,数字字符个数,其他字符个数
import string
s=input('bbkgjb:')
letters=0
space=0
digit=0
others=0
for ch in s:
if ch.isalpha():
letters+=1
elif ch.isspace():
space+=1
elif ch.isdigit():
digit+=1
else:
others+=1
print (letters,space,digit,others)
.lamba 实现两数求最值
Max=lambda x,y:(x>y)*x+(y>x)*y
Min=lambda x,y:(x<y)*x+(y<x)*y
if __name__=='__main__':
print ('max={0},min={1}'.format(Max(10,2),Min(10,2)))