How to Check If String Contains Word in 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...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- How to Generate Random String in Python?
- Python Remove Character from List of Strings Example
- Python Generate List of Random Strings Example
- How to Remove All String Values from List in Python?
- How to Get Only String from a List in Python?
- Python Convert List to String with Space Example
- Python String Replace Space with Comma Example
- Python String Replace Space with Dash Example
- Python String Replace Tab with Space Example
- Python String Replace Double Quotes with Single Quotes Example
- Python String Replace All Numbers Example
- Python Replace First Character Occurrence in String Example
- Python Replace Last Occurrence in String Example