Python count() 方法
2017-10-17 18:33
190 查看
描述
count() 方法用于统计字符串中某个子字符串出现的次数,可选参数为开始搜索与结束搜索的位置索引。语法
count() 方法语法:S.count(sub[,start=0[,end=len(S)]])
参数
sub -- 搜索的子字符串。S -- 父字符串。
start -- 可选参数,字符串开始搜索的位置索引,默认为0。(可单独指定)
end -- 可选参数,字符串结束搜索的位置索引,默认为字符串的长度。(不能单独指定)
返回值
该方法返回子字符串在字符串中出现的次数。实例
以下实例展示了 count() 方法的实例:#!/usr/bin/python3 S="www.runoob.com" sub='o' print ("S.count('o') : ", S.count(sub)) sub='run' print ("S.count('run', 0, 10) : ", S.count(sub,0,10))
以上实例输出结果如下:
S.count('o') : 3 S.count('run', 0, 10) : 1
相关文章推荐
- Python中List.count()方法的使用教程
- Python字符串处理之count()方法的使用
- Python统计字符串中某字符出现的次数,count方法比正则表达式更快
- Python 列表 count() 方法
- Python字符串处理之count()方法的使用
- python之count方法错误
- 【人生苦短,我学Python】个人学习笔记——str.count方法
- Python count()方法和Python List count()方法
- python中count()方法
- Python 元组 count() 方法
- 关于Python中,re.sub(pattern, repl, string, count=0, flags=0)方法的个人理解
- Python中List.count()方法的使用教程
- 【Python】Python3 List count()方法
- 图像标注工具labelImg安装方法(win10+Python3.5)
- Python学习笔记:魔术方法详解
- Python实现partial改变方法默认参数
- python中实现定制类的特殊方法总结
- python|格式化方法——format()
- Python里disconnect UDP套接字的方法
- Python_Day_02 str内部方法总结