Use the in operator:

if "blah" not in somestring: 
    continue

Note: This is case-sensitive.

Answer from Michael Mrozek on Stack Overflow
🌐
DigitalOcean
digitalocean.com › community › tutorials › python-string-contains
Python String contains | DigitalOcean
Learn how to check if one Python string contains another using the contains () method. This case-sensitive instance method returns True or False based on …
Discussions

How to check if a string contains a character in a list
Use a loop , iterate through the list, check for existence of the character . More on reddit.com
🌐 r/learnpython
7
3
February 19, 2022
Is there a way to check if a string is a number?
Nobody mentioned str.isnumeric()... More on reddit.com
🌐 r/learnpython
36
30
September 8, 2024
is string.find(substring) time complexity of O(n) or (O*m)?
It doesn't seem to be specified anywhere but I would expect it to be O(n×m) where n is the length of string and m is the length of substring. More on reddit.com
🌐 r/cpp_questions
5
4
May 14, 2019
Why is there no "dotted dict"?
From my point of view, dot notation is for objects, and indexing is for data structures. Using dot notation to access data inside dicts means there will be confusion between actual data and methods/internals (remember, Python doesn't have external visibility controls) and that disallows you to have keys like 'update' (because that's a method and accessing it will be ambiguous) and gives you a thousand more ways to shoot yourself in the foot. JavaScript made the same mistake with objects vs. dicts and backfired for them. More on reddit.com
🌐 r/Python
41
1
August 29, 2014
🌐
Spark By {Examples}
sparkbyexamples.com › home › python › python string contains
Python String Contains - Spark By {Examples}
May 31, 2024 - In this article, we will discuss different ways to check whether the given substring exists in the string or not. 1. Quick Examples of string contains
🌐
Real Python
realpython.com › python-string-contains-substring
How to Check if a Python String Contains a Substring – Real Python
September 10, 2025 - Python counted how often the substring appears in the string and returned the answer. The text contains the substring four times. But what do these substrings look like? You can inspect all the substrings by splitting your text at default word borders and printing the words to your terminal using a for loop: ... >>> for word in file_content.split(): ... if "secret" in word: ... print(word) ... secret secret. secret, secretly · In this example, you use .split() to separate the text at whitespaces into strings, which Python packs into a list.
🌐
AskPython
askpython.com › python › string › python-string-contains
Python String contains: Check if String Contains Substring - AskPython
April 27, 2023 - The ‘in’ operator, find(), and index() methods are frequently used to check for a substring within a string by developers and we have attached the link to our tutorial on each above-mentioned string method so that you can read them too, but for this tutorial, we will be using the built-in function __contains__(). The Python string __contains__() function can be used with a string object, it takes a substring as an argument and returns True if the substring is present in the string.
🌐
Bacancy Technology
bacancytechnology.com › qanda › python › python-string-contains
How does Python string contains substring method?
For example, the following code checks if the string “hello” contains the substring “ell” using a regular expression: import re string = "hello" substring = "ell" pattern = r"ell" if re.search(pattern, string): print("The substring is ...
🌐
CodeConverter
codeconverter.com › articles › python-string-contains
Python String Contains — Every Way to Check (Ranked) | CodeConverter Blog
February 12, 2026 - A return value of 0 means "not found," so you could technically use .count() > 0 as a contains check. But that's doing extra work — it scans the entire string counting occurrences when you only need to know if there's at least one.
Find elsewhere
🌐
iO Flood
ioflood.com › blog › python-string-contains
Python String Contains | Methods and Usage Examples
December 5, 2023 - In this example, we have a string ‘Hello, World!’ and we are checking if it contains the substring ‘World’. The in keyword in Python returns True if the substring exists in the string, and False otherwise.
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.Series.str.contains.html
pandas.Series.str.contains — pandas 3.0.6 documentation
Same as startswith, but tests the end of string. ... Returning a Series of booleans using only a literal pattern. >>> s1 = pd.Series(["Mouse", "dog", "house and parrot", "23", np.nan]) >>> s1.str.contains("og", regex=False) 0 False 1 True 2 False 3 False 4 False dtype: bool
🌐
GeeksforGeeks
geeksforgeeks.org › python › check-if-string-contains-substring-in-python
Check if String Contains Substring in Python - GeeksforGeeks
December 20, 2025 - The in operator in Python checks if one string occurs within another. It evaluates to True if the substring is present in the main string, otherwise False. ... s = "Geeks welcome to the Geek Kingdom!" if "Geek" in s: print("Substring found!") else: print("Substring not found!") if "For" in s: print("Substring found!") else: print("Substring not found!") ... Substring found! Substring not found! ... The operator.contains() function checks for substring presence in a string programmatically.
🌐
ReqBin
reqbin.com › code › python › wzo2s8ib › python-string-contains-example
How to check if a string contains a substring in Python?
December 20, 2022 - To check if a Python string contains the desired substring, you can use the "in" operator or the string.find() method.
🌐
Codecademy
codecademy.com › article › how-to-check-if-a-string-contains-a-substring-in-python
How to Check if a String Contains a Substring in Python | Codecademy
For more detailed checks, like finding the position of the substring or avoiding exceptions, methods like .find(), .index(), and .contains() come into play. If you want to learn more about strings and string operations in Python, check out the Learn Python 3 course on Codecademy. Yes, the in operator is case-sensitive. For example, “Apple” in “Pineapple” returns False because of the capital “A”.
🌐
LearnDataSci
learndatasci.com › solutions › python-string-contains
Python String Contains – See if String Contains a Substring – LearnDataSci
The easiest and most effective way to see if a string contains a substring is by using if ... in statements, which return True if the substring is detected. Alternatively, by using the find() function, it's possible to get the index that a substring starts at, or -1 if Python can't find the ...
🌐
Afternerd
afternerd.com › blog › python-string-contains
How to Check if a Python String Contains Another String? - Afternerd
May 25, 2020 - If you are coming to Python from Java, for instance, you might have used the contains method to check if some substring exists in another string. In Python, there are two ways to achieve this. The easiest way is via Python’s in operator. Let’s take a look at this example.
🌐
Udemy
blog.udemy.com › home › it & development › software development › the many ways to check if a python string contains a substring
Ways to Check if a Python String Contains a Substring - Udemy Blog
April 14, 2026 - What if the string could contain the substring more than once? Here is the syntax of the find method: We can use the two other arguments to set a starting and ending point in the string we are searching. Here is an example: The code above will return the start index of the second occurrence of the substring “sea.” · 100 Days of Code™: The Complete Python Pro Bootcamp Dr.
🌐
Java Code Geeks
examples.javacodegeeks.com › home › web development › python
Python String contains() method Tutorial - Java Code Geeks
March 2, 2022 - Download You can download the full source code of this example here: Python String contains() method Tutorial
🌐
DataCamp
datacamp.com › tutorial › python-string-contains
Python String Search and Replace: in, .find(), .index(), .count(), and .replace() | DataCamp
March 31, 2026 - Python’s text strings are Unicode. Substring operations are case-sensitive by default and implemented in C for speed. The most direct way to test if text appears inside a string is the in operator, which returns a Boolean using the string’s __contains__() implementation.
🌐
Python Morsels
pythonmorsels.com › substring-check
Substrings in Python: checking if a string contains another string - Python Morsels
July 18, 2026 - What if you need to check whether one string contains another specifically at the beginning or the end of the string? You can use the string startswith method to check whether one string starts with another string: >>> whole = "I enjoy writing Python code." >>> whole.startswith("You ") False >>> whole.startswith("I ") True
🌐
Scaler
scaler.com › home › topics › how to check if string contains substring in python?
How to Check if String Contains Substring in Python? - Scaler Topics
March 15, 2024 - Time Complexity: The time complexity is O(n + m), n = length of the main string, and m is the number of words in the split string. This method splits the string and then iterates over the words to perform the search. In this example, the variable substring contains Python as a substring and will check whether it is present in main_string using the split method.