ItSolutionStuff.com

How to Check If String Contains Word in Python?

By Hardik Savani • October 30, 2023
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: Python
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

How to Generate Random String in Python?

Read Now →

Python Remove Character from List of Strings Example

Read Now →

Python Generate List of Random Strings Example

Read Now →

How to Remove All String Values from List in Python?

Read Now →

How to Get Only String from a List in Python?

Read Now →

Python Convert List to String with Space Example

Read Now →

Python String Replace Space with Comma Example

Read Now →

Python String Replace Space with Dash Example

Read Now →

Python String Replace Tab with Space Example

Read Now →

Python String Replace Double Quotes with Single Quotes Example

Read Now →

Python String Replace All Numbers Example

Read Now →

Python Replace First Character Occurrence in String Example

Read Now →

Python Replace Last Occurrence in String Example

Read Now →