find substring():
- The find substring is used to find the substring from the string.
- Substring is the piece of characters from the string.
- If the string consists of the given string then it returns the index number of the substring.
- The string must be enclosed with single or double-quotes.
- It returns -1 if the substring does not found instead of an error.
- find() has 3 parameters,they are:
- value: The value to be search
- start: from where to search
- end: from where to stop searching.
Syntax: str.find(value,start,end)
#write a python code to demonstrate the find substring function.
- txt="learning is a life time process"
- txt=txt.find("i")
- print(txt)
- s="apple"
- s=s.find("b")
- print(s)
Output: 5
-1
No comments