实现:

s = 'Hello,everyoneToday,LetUsLEARNPython'

统计小写字母的个数

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

转化为大写

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

实现任意字符的替换

while True: op = input("操作ITEM\n替换 1\n结束 0\n") if op == "0": break elif op == "1": old_char = input("请输入要替换的字符:") new_char = input("请输入新的字符:") s = s.replace(old_char, new_char) print("替换后的字符串为:", s) else: print("输入有误,请重新输入")

有字符串s=HelloeveryoneTodayLetUsLEARNPython’统计其中小写字母的个数。将字符串转化为大写并实现任意字符的替换。小写字母数量为24当前字符串为HELLOEVERYONETODAYLETUSLEARNPYTHON操作ITEM替换 1结束 0用Python

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

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