count()函数用于查找字符串中指定子串的出现次数,参数为指定子串
str1 = "this is great"
print(str1.count(" "))
# 2
同时count()函数也可以指定源字符串下标范围
str1 = "this is great"
print(str1.count(" ", 0, 6))
# 1
这里通过指定下标范围为0-6所以只查了前7个字符中空格的数量,为1
count()函数用于查找字符串中指定子串的出现次数,参数为指定子串
str1 = "this is great"
print(str1.count(" "))
# 2
同时count()函数也可以指定源字符串下标范围
str1 = "this is great"
print(str1.count(" ", 0, 6))
# 1
这里通过指定下标范围为0-6所以只查了前7个字符中空格的数量,为1