Python基础语法-菜鸟教程-函数用法:count()

3.count()用法
1)用法解释
def count(self, sub, start=None, end=None): # real signature unknown; restored from doc
“”"
S.count(sub[, start[, end]]) -> int

Return the number of non-overlapping occurrences of substring sub in
string S[start:end]. Optional arguments start and end are
interpreted as in slice notation.
“”"
return 0
2)实例解析
eg:有如下实例
str1=“one two three sfokur”
str2=“o”
print(str1.count(str2))
print(str1.count(str2, 0, 7))

上述实例的输出结果为:
3
2

发布了25 篇原创文章 · 获赞 0 · 访问量 216

猜你喜欢

转载自blog.csdn.net/qq_33410995/article/details/104182052