01-计算字符个数-1

写出一个程序,接受一个由字母和数字组成的字符串,和一个字符,然后输出输入字符串中含有该字符的个数。不区分大小写。

Python lower() 方法转换字符串中所有大写字符为小写。

Python count() 方法用于统计字符串里某个字符出现的次数。

# 方法1:
str1 = input()
str2 = input()
str1 = str1.lower()
str2 = str2.lower()
 
j = 0
for i in range(len(str1)):
    if str1[i]==str2:
        j +=1
print(j)

# 方法2:
a=input().lower()
b=input().lower()
print(a.count(b))

 

原文地址:https://www.cnblogs.com/summer1019/p/11141155.html