Welcome to follow Me blog: Cloud Dreamer
Describe
The Find () method detects whether the string contains substrings of STR, and if you specify beg (start) and end (end) ranges, the check is included in the specified range, and if the specified range contains the specified index value, the return index value is the starting position in the string. Returns 1 if the index value is not included.
Grammar
str.find(str, beg=0, end=len(string))
Parameters
- STR--The string to retrieve
- Beg--Start index, default value is 0
- End--ending index, default to string length
return value
Returns the start index if a substring is found, otherwise 1
Instance
Example code:
#!/usr/bin/python3="Runoob example....wow!!!"="exam";print (str1.find(str2))print5))print10))
Return:
7
7
-1
>>>=‘abca‘>>>print(info.find(‘a‘)) # 从下标0开始,查找在字符串里第一个出现的子串,返回结果:00>>>print(info.find(‘a‘1)) # 从下标1开始,查找在字符串里第一个出现的子串:返回结果33>>>print(info.find(‘3‘)) # 查找不到返回-1-1>>>
Find () Python