# strings 代表返回值内某个字母,或字符串
strings.isalnum() #所有字符都是数字或者字母
strings.isalpha() #所有字符都是字母
strings.isdigit() #所有字符都是数字
strings.islower() #所有字符都是小写
strings.isupper() #所有字符都是大写
strings.istitle() #所有单词都是首字母大写,像标题
strings.isspace() #所有字符都是空白字符、\t、\n
判断一个返回值内有多少小写字母
# 符合要求的
strings = {'cad', 'PE ', 'Window', 'FM', 'hello', 'world','flowers'}
# strings = 'djhsHUJ768JHJjsk'
# strings = ['fsDfs', 'DFF', 'SSFA']
# strings = {'name':'XiaoMing', 'site':'BeiJing'}
# 不符合要求的
# strings = 3.1415926
# strings = 235346354235
def test():
if isinstance(strings, set):
num = 0
for word in strings:
if word.isalpha: # 判断str内包含的都是字母
di = tuple(word)
for y in di:
if y.islower(): # 判断是否为小写
num += 1
else:
print('并不是所有字符都是字母')
print(num)
if isinstance(strings, dict):
num1 = 0
for keys, values in strings.items():
for word in values:
if word.isalpha: # 判断str内包含的都是字母
di = tuple(word)
for y in di:
if y.islower(): # 判断是否为小写
num1 += 1
else:
print('并不是所有字符都是字母')
print(num1)
if isinstance(strings, list):
num2 = 0
for word in strings:
if word.isalpha: # 判断str内包含的都是字母
di = tuple(word)
for y in di:
if y.islower(): # 判断是否为小写
num2 += 1
else:
print('并不是所有字符都是字母')
print(num2)
if isinstance(strings, str):
num3 = 0
if strings.isalpha: # 判断str内包含的都是字母
s = tuple(strings)
for y in s:
if y.islower(): # 判断是否为小写
num3 += 1
else:
print('并不是所有字符都是字母')
print(num3)
else:
pass
test()