我是靠谱客的博主 动听小甜瓜,这篇文章主要介绍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

最后

以上就是动听小甜瓜最近收集整理的关于Python基础语法-菜鸟教程-函数用法:count()的全部内容,更多相关Python基础语法-菜鸟教程-函数用法内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(51)

评论列表共有 0 条评论

立即
投稿
返回
顶部