Categories
Python Answers

How to check if a word is in a string with Python?

Spread the love

Sometimes, we want to check if a word is in a string with Python.

In this article, we’ll look at how to check if a word is in a string with Python.

How to check if a word is in a string with Python?

To check if a word is in a string with Python, we can use the in operator.

For instance, we write:

if 'seek' in 'those who seek shall find':
    print('Success!')

to check if 'seek' is included in 'those who seek shall find'.

Since this is True, 'Success!' is printed.

Conclusion

To check if a word is in a string with Python, we can use the in operator.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *