Check If String Contains Word in Python Tutorial Example

24-May-2023

.

Admin

Check If String Contains Word in Python Tutorial Example

Hi Dev,

Today our leading topic is checked if the string contains the word in the Python tutorial example. We will look at an example of a Python check string containing words. Step by step explain Python if the string contains the word. I would like to share with you the Python check string contains.

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

Example :


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!

#Python