Given two strings, check if s1 is there in s2.
Input : s1 = geeks s2=geeks for geeks Output : yes Input : s1 = geek s2=geeks for geeks Output : yes
We can iteratively check for every word, but Python provides us an inbuilt function find() which checks if a substring is present in the string, which is done in one line.
find() function returns -1 if it is not found, else it returns the first occurrence, so using this function this problem can be solved.
Method 1: Using user defined function.
Method 2: Using “count()” method:-
Method 3: Using regular expressions
RegEx can be used to check if a string contains the specified search pattern. Python has a built-in package called re, which can be used to work with Regular Expressions.
YES,string 'geek' is present in string 'A geek in need is a geek indeed'
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Python | Check if substring present in string
- Number of Positions to partition the string such that atleast m characters with same frequency are present in each substring
- Check if given words are present in a string
- Check whether the Average Character of the String is present or not
- Queries to check if string B exists as substring in string A
- Check if a string is substring of another
- Check if the given string is shuffled substring of another string
- Check if string can be rearranged so that every Odd length Substring is Palindrome
- Python | Check if element is present in tuple
- Check if string can be made lexicographically smaller by reversing any substring
- Check if there exists a permutation of given string which doesn't contain any monotonous substring
- Python | Check if element is present in tuple of tuples
- Check if the given string of words can be formed from words present in the dictionary
- Python | Frequency of substring in given string
- Python | Remove the given substring from end of string
- Python | All occurrences of substring in string
- Python | Get the string after occurrence of given substring
- Python - String till Substring
- Python | Check if substring is part of List of Strings
- Python - Replace all occurrences of a substring in a string
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.