python学习之count()

定义:

count()方法用于统计对象中,某个字符出现的次数

语法:

str.count(sub, start= 0,end=len(string))

sub:搜索的对象

start和end:搜索的范围,表现为索引号

说明:sub类型要和str类型一致,比如str是字节流,sub也要是字节流。

例子:

>>> s = 'hellowe'
>>> s.count('e',0,8)
2

 

原文地址:https://www.cnblogs.com/leomei91/p/7656468.html