Python Check if a String Contains a Substring

Python3 Examples

Given a string, determine whether the specified substring exists in the string.

Examples

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

Executing the above code produces the output:

Exists!

Python3 Examples

Other Extensions