What kind of string lookup method does python have?
This article will explain in detail what kind of string search methods there are in python. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
1. Find and rfind look for the location of the first and last occurrence of the string, and return-1 if it does not exist.
S = "bird,fish,monkey,rabbit" s.find ('fish') # 5s.rfind (' b') # 20s.find ('tiger') #-1
2. When looking for index and rindex, an exception is thrown if it does not exist.
S = "bird,fish,monkey,rabbit" s.index ('bird') # 0s.rindex (' i') # 21s.index ('tiger') # specified string does not exist substring not found
3. Count returns the number of times a string appears in another string, or 0 if it does not exist.
S = "bird,fish,monkey,rabbit" s.count ('bird') # 1s.count (' b') # 3s.count ('tiger') # 0 this is the end of the article on "what kind of string search method does python have". I hope the above content can be helpful to you so that you can learn more knowledge. if you think the article is good, please share it for more people to see.