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

编程知识 行业动态 更新时间:2024-06-13 00:20:50

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()

本文发布于:2023-03-30 16:49:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/892f3c2ee09592adbdb4d7431355b24e.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:菜鸟   语法   函数   基础   教程

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!