本文共 542 字,大约阅读时间需要 1 分钟。
要解决这个问题,我们需要编写一个程序来统计给定字符串中包含指定字符的个数,并且不区分大小写。
s = input().strip()c = input().strip()target = c.upper()count = 0for char in s: if char.upper() == target: count += 1print(count)
input().strip()
读取字符串和目标字符,去掉两端的空白字符。target
变量中。count
初始化为 0。target
,如果相等则增加计数器。转载地址:http://aerfk.baihongyu.com/