代码实现:

s='Hello,everyone,Today,LetUsLEARNPython'

统计小写字母个数

count = 0 for c in s: if c.islower(): count += 1 print("小写字母数量为:", count)

转化为大写并替换字符

print("当前字符串为:") print(s.upper())

while True: print("") print("操作 ITEM") print("替换 1") print("结束 0") print("") choice = int(input("请输入要执行的操作:")) if choice == 0: break elif choice == 1: old_str = input("请输入要替换掉的字符") new_str = input("请输入要替换为的字符") s = s.replace(old_str, new_str) print("新字符串为:") print(s.upper()) else: print("输入有误,请重新输入。")

有字符串:s=HelloeveryoneTodayLetUsLEARNPython统计其中小写字母的个数。将字符串转化为大写并实现任意字符的替换。小写字母数量为:24当前字符串为:HELLO EVERYONE TODAY LETUSLEARNPYTHON操作 ITEM替换 1结束 0米请输入要执行的操作:1请输入要替换掉的字符HELLO请输入要替换为的字符HI新字符串为:HIEVERYONE TO

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

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