Python | Check if a substring is present in the given string

Python Methods and Functions | String Variables

Examples :

 Input: s1 = geeks s2 = geeks for geeks Output: yes Input: s1 = geek s2 = geeks for geeks Output: yes 

We can iteratively check each word, but Python provides us with a built-in function isupper-lower-upper-swapcase-title /> find (), which checks for the presence of a substring in a string, which is done in one line. 
The find () function returns -1 if it is not found, otherwise it returns the first occurrence, so this function can solve this problem.

# a function to check if the small line is
# there in the big line

def check (string, sub_str):

if (string.find (sub_str) = = - 1 ):

print ( "NO" )

else :

print ( " YES " )

# driver code

string = " geeks for geeks "

sub_str = " geek "

check (string, sub_str)