How to Check If String Contains Word in Python?

By Hardik Savani October 30, 2023 Category : Python

Hi Friends,

In this example, you will learn python check string contains word. I would like to share with you python if string contains word. if you want to see an example of python check string contains then you are in the right place. It is a simple example of how to check if string contains word in python.

In this example, we will use In Operator to check string contains word or not. we will take "myString" variable with some string and then we will check "findString" variable to check that words exist on not in string. let's see a simple example.

You can use these examples with python3 (Python 3) version.

let's see below a simple example with output:

Example 1:

main.py

myString = "This is ItSolutionStuff.com"
findString = "Solution"
  
# Python check string contains word
if findString in myString:
    print("Found!")
else:
    print("Not found!")

Output:

Found!

I hope it can help you...

Tags :
Shares