String search functions in Python

22-02-23 Ahmed Obaid 1036 0

Python provides a lot of built-in functions for manipulating strings. String in Python is immutable, so all these functions return a new string and the original string remains unchanged. You do not have to memorize all of these functions that we will mention in this article. All you have to know is how to use these functions and what they can do. All of these functions are present by default in the str class inside the builtins.py file, which is included in the Python interpreter. 





































functio name description Link
count()  The count () function returns the number of occurrences of the substring passed to the parameter . The count()  function takes three  parameters , the first is a substring , the second is the starting index and the third is the last index of the range. Beginning and ending are both optional while the substring is required. read more  
find()  The find () function returns the index number of the first occurrence of a substring (plain text) in the specified string (case sensitive). If the substring is not found, it returns -1. read more  
rfind()  The rfind()  function returns the index number of the last occurrence of a substring (plain text) in the specified string (case sensitive). If the substring is not found, it returns -1. The difference between it and the find() function is that it starts the search process from the last index in the text to be searched for to the first index in it. read more  
index()  The index ()  function returns the index number of the first occurrence of a substring (plain text) in the specified string (case sensitive). It's the same as the find() function except that if the substring is not found, it raises a ValueError if the substring is not found or if the index is outside the scope of the search read more  
rindex()  The rindex()  function returns the index number of the last occurrence of a substring (plain text) in the specified string (case sensitive). It's the same as the rfind() function except that if the substring is not found, it raises a ValueError if the substring is not found or if the index is outside the scope of the search . read more  


 



Tags


Python python data types Python String string methods python String search functions in Python python string count method python string find method python string rfind method python string index method python string rindex method

Share page