str内置函数很多语言字符串使用string表示,python里面使用str表示字符串查找类,find,index,islower(判断小写)find:查找字符串中是否包括一个字符串index:跟find的唯一区别是index如果找不到会引发异常rfind,lfind:从左开始查或者从右开始查s = "Zhao min is very beautiful and Zou kexin...
摘要由CSDN通过智能技术生成
str内置函数
很多语言字符串使用string表示,python里面使用str表示
字符串查找类,find,index,islower(判断小写)
find:查找字符串中是否包括一个字符串
index:跟find的唯一区别是index如果找不到会引发异常
rfind,lfind:从左开始查或者从右开始查
s ="Fen fen is very beautiful and Zou kexin is very fascinating"
s1 ="Fen fen"# 返回第一次发现这个字符串的位置
s.find(s1)
s2 ="xiaofen"# 返回-1表示没有找到
s.find(s2)
-1
注意区别
help(str.find)
Help on method_descriptor:
find(...)
S.find(sub[, start[, end]]) -> int
Return the lowest index in S where substring sub is found,
such that sub is contained within S[start:end]. Optional
arguments start and end are interpreted as in slice notation.
Return -1 on failure.
help(str.index)
Help on method_descriptor:
index(...)
S.index(sub[, start[, end]]) -> int
Return the lowest index in S where substring sub is found,
such that sub is contained within S[start:end]. Optional
arguments start and end are interpreted as in slice notation.
Raises ValueError when the substring is not found.
str内置函数很多语言字符串使用string表示,python里面使用str表示字符串查找类,find,index,islower(判断小写)find:查找字符串中是否包括一个字符串index:跟find的唯一区别是index如果找不到会引发异常rfind,lfind:从左开始查或者从右开始查s = "Zhao min is very beautiful and Zou kexin...