Easy Tutorial
❮ Ref Set Issubset Python File Tell ❯

Python Check if Substring Exists in a String

Python3 Examples

Given a string, determine if a specified substring exists within this string.

Example

def check(string, sub_str): 
    if (string.find(sub_str) == -1): 
        print("Does not exist!") 
    else: 
        print("Exists!") 

string = "www.tutorialpro.org"
sub_str ="tutorialpro"
check(string, sub_str)

Executing the above code outputs:

Exists!

Python3 Examples

❮ Ref Set Issubset Python File Tell ❯