小白教程
所有教程
关于
Search
172.71.255.11
172.71.255.11
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Python3 string count”的源代码
本页内容
上一节:
Python3_string_center
下一节:
Python3_string_decode
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:count(str, beg= 0,end=len(string))}}[[Category:python3 string|3]] = Python3 count()方法 = [[python3 string|Python3 字符串]] == 描述 == count() 方法用于统计字符串里某个字符出现的次数。可选参数为在字符串搜索的开始与结束位置。 == 语法 == count()方法语法: <sample title="" desc="" lang="python" hererun="1"> str.count(sub, start= 0,end=len(string)) </sample> == 参数 == * sub -- 搜索的子字符串 * start -- 字符串开始搜索的位置。默认为第一个字符,第一个字符索引值为0。 * end -- 字符串中结束搜索的位置。字符中第一个字符的索引为 0。默认为字符串的最后一个位置。 == 返回值 == 该方法返回子字符串在字符串中出现的次数。 以下实例展示了count()方法的实例: <sample title="" desc="" lang="python" hererun="1"> #!/usr/bin/python3 str="www.xiaobai.wang" sub='o' print ("str.count('o') : ", str.count(sub)) sub='run' print ("str.count('run', 0, 10) : ", str.count(sub,0,10)) </sample> 以上实例输出结果如下: <sample title="" desc="" lang="python" hererun="1"> str.count('o') : 3 str.count('run', 0, 10) : 1 </sample> [[python3 string|Python3 字符串]]
返回至“
Python3 string count
”。
上一节:
Python3_string_center
下一节:
Python3_string_decode