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'
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- 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
- Find if a given string can be represented from a substring by iterating the substring “n” times
- Partition given string in such manner that i'th substring is sum of (i-1)'th and (i-2)'th substring
- Check if the given string of words can be formed from words present in the dictionary
- Check if given words are present in a string
- Check if binary representations of 0 to N are present as substrings in given binary string
- Check if the given string is shuffled substring of another string
- Check if given string is a substring of string formed by repeated concatenation of z to a
- Length of the largest substring which have character with frequency greater than or equal to half of the substring
- Minimum length of substring whose rotation generates a palindromic substring
- Check whether the Average Character of the String is present or not
- Queries to check if string B exists as substring in string A
- Remove characters from the first string which are present in the second string
- Find the character in first string that is present at minimum index in second string
- Most frequent word in first String which is not present in second String
- Find the longest sub-string which is prefix, suffix and also present inside the string
- Find the longest sub-string which is prefix, suffix and also present inside the string | Set 2
- Check whether a given column is present in a Pandas DataFrame or not
- Check if there exists a permutation of given string which doesn't contain any monotonous substring
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.