2024-11-06 02:40:13
#如何使生成器函数来用元组返回一个字符串大写字母个数和小写字母个数
def getUorL(s):
# [A-Z]是匹配内容,str是待匹配的对象
rtn = f"大写字母个数: {len(re.findall('[A-Z]',s))}"
yield rtn
# [a-z]是匹配内容,str_是待匹配的对象
rtn = f"小写字母个数: {len(re.findall('[a-z]',s))}"
yield rtn
str = "10ABC23sD~45ffe67e;oo++"
#第一次返回大写
g = getUorL(str)
print(next(g))
#第二次返回小写
print(next(g))
2024-11-06 03:10:13