网站推广.NET

网站推广.NET

python中count函数的用法详解

来源:互联网 知识问答 0

python中count函数的用法    

count()函数

描述:统计字符串里某个字符出现的次数,可以选择字符串索引的起始位置和结束位置。

语法:str.count("char", start,end)  或 str.count("char") 

返回值:整型

立即学习“Python免费学习笔记(深入)”;

参数说明:

程序示例:

str = "i love python,i am learning python"print(str.count("i")) #star 和end 为默认参数print(str.count("i",2)) # star值为2,end值为默认参数print(str.count("i",2,5)) #star值为2,end值为5print(str.count("am"))  #多字符统计

程序运行结果:

320

推荐学习:Python教程

python count

抱歉,评论功能暂时关闭!