Python 中的 count(str, beg= 0,end=le

首页 / Python2入门教程 / Python 中的 count(str, beg= 0,end=le

Python count()返回[start,end]范围内substring sub的出现次数。可选参数start和end被解释为片表示法中的参数。

count - 语法

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

count - 返回值

以一串长度和宽度为中心。

count - 示例

#!/usr/bin/python

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

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

深入浅出计算机组成原理 -〔徐文浩〕

Redis核心技术与实战 -〔蒋德钧〕

爱上跑步 -〔钱亮〕

讲好故事 -〔涵柏〕

深入C语言和程序运行原理 -〔于航〕

深入浅出分布式技术原理 -〔陈现麟〕

说透低代码 -〔陈旭〕

人人都用得上的数字化思维课 -〔付晓岩〕

B端产品经理入门课 -〔董小圣〕

好记忆不如烂笔头。留下您的足迹吧 :)