目录
1. count(sub[,start[,end]])
返回 sub 在字符串中不重叠的出现次数,可选参数 start 和 end 用于指定起始和结束位置
x = '01233210123abccbabc'
#查询数据sub必须为字符串,否则报错
x.count(1)
Traceback (most recent call last):
File "<input>", line 1, in <module>
TypeError: must be str, not int
x.count('0')
2
x.count('1')
3
x.count('4')
0
x.count('0123')
2
x.count('3210')
1
x.count('01',0)
2
x.count('01',1)
1
x.count('01',9)
0
x.count('01',7)
1
x.count('01',8)
0
x.count('01',0,1)
0
x.count('01',0,2)
1
x.count('01',0,8)
1
x.count('01',0,9)
2
2. find(sub[,start[,end]])
在字符串中查找 sub 子字符串,返回匹配的最低索引值,即从从左至右的第一个匹配字符串索引;
可选参数 start 和 end 用于指定起始和结束位置;
如果未能匹配子字符串,返回 -1;
单个子字符返回字符位置索引,子字符串返回第一个字符位置索引;
子字符串必须在被查询范围(全字符串 或 start至end-1范围)整段被完整匹配;
终止值大于起始值,查询不到,返回-1;
起始值存在,终止值可以为空;终止值存在,起始值为空则报错;
x =