count函数 python

python如何用count函数

九三
260
2021-02-09 14:19:57
栏目: 编程语言

python如何用count函数

在python中使用count函数的方法

count:count()函数的作用是用于统计字符串里某个字符出现的次数。

count()函数语法:

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

参数:

sub:需要搜索的子字符串。

start :字符串开始搜索的位置。

end:字符串中结束搜索的位置。

count()函数使用方法:

str = "this is string example....wow!!!";

sub = "i";

print "str.count(sub, 4, 40) : ", str.count(sub, 4, 40)

sub = "wow";

print "str.count(sub) : ", str.count(sub)

输出结果为:

str.count(sub, 4, 40) : 2

str.count(sub) : 1

0
看了该问题的人还看了