Python_API_String Services_string.count
来源:互联网 发布:怎样设置淘宝地理位置 编辑:程序博客网 时间:2024/06/08 05:52
API文档:
string.count(s, sub[, start[, end]])
Return the number of (non-overlapping) occurrences of substring sub in string s[start:end]. Defaults for start and end and interpretation of negative values are the same as for slices.
翻译文档:
s:被匹配的字符串
sub:匹配的字符串
start:字符串的开始位置
end:字符串结束为止
这个方法和string.find的搜索方法是用上基本一致,但是返回的是子字符串的出现次数,没有找到则返回0
例子:
#! /usr/bin/env python
#coding=utf-8
import string
line1="a <nd abc nd > "
print string.count(line1,'nd')
print string.count(line1,'safsaf')
输出:
2
0
- Python_API_String Services_string.count
- Python_API_String Services_string.strip
- Python_API_String Services_string.find
- Python_API_String Services_string.index
- Python_API_String Services_string.replace
- Python_API_String Services_string.split
- Python_API_String Services_string.lower
- Python_API_String Services_string.upper
- Python_API_String Services_re.sub
- Python_API_String Services_re.search
- Python_API_String Services_re.compile
- Count
- COUNT
- count
- Count
- count
- count
- count
- 误删文件恢复方法
- 具有跨浏览器兼容的事件处理javascript脚本
- 写给自己的第一篇博文
- AVL树基本操作
- 简单、常用的字符串转二进制代码
- Python_API_String Services_string.count
- U盘病毒-----文件变为受保护的操作系统隐藏文件
- Python - string
- 怎么判断一帧的开始
- 通过script标签实现JSONP跨域调用
- 现实迷途 第四章 小人物,大道理
- 单例模式剖析
- Future 模式(异步调用)
- IIC协议