To check if a word is in a string in Python, use the in operator for a quick test, or re.search() with \b word boundaries when it has to be the whole word, not part of a longer one:
"plot" in text # quick substring test
re.search(r"\bplot\b", text, re.IGNORECASE) # whole word, any case
I ran each script in Command Prompt on Python 3.12.5, with customer reviews, a support ticket and a billing email as test text.
You’ll see the in trap first, then whole-word checks with split() and regex, case, and several words at once.
Check a word with the in operator
in returns True when the text appears anywhere in the string. It’s a substring test, though, so a short word can match inside a longer one:
review = "The scatter plot made the data easy to read."
print("cat" in review) # True - 'cat' sits inside 'scatter'
print("plot" in review) # True
print("chart" in review) # False
print("chart" not in review) # True
Output:
True
True
False
True

"cat" in review is True only because of the word scatter, while chart isn’t found at all.If any match is fine, that’s enough. My guide on checking if a Python string contains a substring goes deeper.
Match whole words with split() and punctuation removal
A list of words makes in compare whole words. But split() only breaks on spaces, so fair! keeps its punctuation. Strip it with str.translate() first:
import string
review = "Shipping was fast, and the price ($24.99) was fair!"
words = review.lower().split()
print(words)
print("fair" in words) # False - the word is 'fair!'
table = str.maketrans("", "", string.punctuation)
clean = review.lower().translate(table).split()
print(clean)
print("fair" in clean) # True
print("ship" in clean) # False - whole words only
Output:
['shipping', 'was', 'fast,', 'and', 'the', 'price', '($24.99)', 'was', 'fair!']
False
['shipping', 'was', 'fast', 'and', 'the', 'price', '2499', 'was', 'fair']
True
False

translate() it is, and ship doesn’t match shipping.It’s fine for plain text. More splitting options are in splitting a sentence into a list of words in Python.
How do I check for an exact word with regex?
A regex with \b on both sides matches only the whole word, and punctuation is handled for you. re.escape() stops . or + acting as regex symbols:
import re
def has_word(text, word):
pattern = rf"\b{re.escape(word)}\b"
return re.search(pattern, text, flags=re.IGNORECASE) is not None
ticket = "Customer in Austin, TX asked for a Refund on order #4521 (May 4, 2026)."
print(has_word(ticket, "refund")) # True - case ignored
print(has_word(ticket, "fun")) # False - inside 'Refund'
print(has_word(ticket, "TX")) # True - next to a comma
print(has_word(ticket, "order")) # True
m = re.search(r"\brefund\b", ticket, flags=re.IGNORECASE)
print(m.group(), "found at index", m.start())
Output:
True
False
True
True
Refund found at index 35

m.start() gives the position. For every position, see finding all occurrences of a substring in Python.
Make the word check case-insensitive
in and re.search() are case-sensitive. With in, use casefold() (a stronger lower()); with regex, pass re.IGNORECASE:
"Refund" in ticket # case-sensitive
"refund" in ticket.casefold() # case-insensitive
Comparing whole strings without case is a separate job, covered in comparing strings in Python.
Check if a string contains any or all of several words
For a keyword list, collect the matches, then use any() or all(). re.findall() counts whole words; find() returns -1 on no match:
import re
def found_words(text, words):
return [w for w in words if re.search(rf"\b{re.escape(w)}\b", text, re.IGNORECASE)]
email = "Your invoice for $149.00 is past due. Please pay by June 30, 2026."
keywords = ["invoice", "due", "refund", "pay"]
print(found_words(email, keywords))
print("any:", any(w in found_words(email, keywords) for w in keywords))
print("all:", all(w in found_words(email, keywords) for w in keywords))
print("count of 'pay':", len(re.findall(r"\bpay\b", email, re.IGNORECASE)))
print("find('due'):", email.find("due"), " find('late'):", email.find("late"))
Output:
['invoice', 'due', 'pay']
any: True
all: False
count of 'pay': 1
find('due'): 33 find('late'): -1

any() is True and all() is False because refund is missing.To delete a word once you’ve found it, see removing specific words from a string in Python.
You might also find these string checks handy:
- Check if a string starts with a substring in Python
- Find a character in a string using Python
- Count words in a file in Python
- Check if a string contains a special character in Python
Frequently asked questions
How do I check if a word is in a string in Python?
Use "word" in text for a quick check, or re.search(r"\bword\b", text) to match only the whole word.
Why does “cat” in text return True when the word isn’t there?
in checks substrings, so it matches cat inside scatter. Use a \b regex for whole words.
How do I check for a word without caring about case?
Use "word" in text.casefold(), or pass re.IGNORECASE to re.search().
How do I check if a string contains any word from a list?
Use any(w in text for w in words).
How do I find the position of a word in a string?
text.find(word) returns the first index or -1; re.search() gives it through .start().
Where is the \b word boundary documented?
See the re module in the Python docs.

Bijay Kumar is a 13-time Microsoft MVP with more than 18 years in software development, and the founder of Python Guides and TSinfo Technologies. He started out building .NET and SharePoint solutions at HP, TCS and KPIT before moving into Python, machine learning and AI, and he also builds web apps with TypeScript and React. He writes the tutorials here himself, and every example is run before publishing so you see the real output. More about Bijay · Microsoft MVP profile · LinkedIn