码迷,mamicode.com
首页 > 编程语言 > 详细

python学习之count()

时间:2017-10-12 16:15:54      阅读:228      评论:0      收藏:0      [点我收藏+]

标签:tar   size   sub   soft   类型   csharp   span   ack   sof   

定义:

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

语法:

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

sub:搜索的对象

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

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

例子:

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

 

 

python学习之count()

标签:tar   size   sub   soft   类型   csharp   span   ack   sof   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!