统计小写字母个数:

s = 'Hello,everyone,Today,LetUsLEARNPython'
count = len([char for char in s if char.islower()])
print(count)  # 输出:17

将字符串转化为大写:

s = s.upper()
print(s)  # 输出:'HELLO,EVERYONE,TODAY,LETUSLEARNPYTHON'

实现任意字符的替换:

s = s.replace(',', '-')
print(s)  # 输出:'HELLO-EVERYONE-TODAY-LETUSLEARNPYTHON'
用Python 有字符串:s = HelloeveryoneTodayLetUsLEARNPython统计其中小写字母的个数。将字符串转化为大写并实现任意字符的替换。

原文地址: https://www.cveoy.top/t/topic/bvCd 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录