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?
value = input() try: float(value) except ValueError: #somethin else: #something 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
🌐
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.
🌐
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
🌐
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.
🌐
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”.
🌐
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.
🌐
LearnDataSci
learndatasci.com › solutions › python-string-contains
Python String Contains – See if String Contains a Substring – LearnDataSci
Today we'll take a look at the various options you've got for checking if a string contains a substring. We'll start by exploring the use of if ... in statements, followed by using the find() function. Towards the end, there is also a section on employing regular expressions (regex) with re.search() to search strings. ... Go from side-hustling to earning enough to quit your job. Check it out → · The example above demonstrated a quick way to find a substring within another string using an if ...
🌐
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 - The python str class has a __contains__() method that will check if a python string contains a substring. It will return true if it’s found and will return false if it’s not. You will notice that the method name is wrapped in two underscores.
🌐
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
🌐
Pandas
pandas.pydata.org › pandas-docs › stable › reference › api › pandas.Series.str.contains.html
pandas.Series.str.contains — pandas 3.0.5 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
🌐
Analytics Vidhya
analyticsvidhya.com › home › learn how to check if a string contains a substring in python
Learn How to Check If a String Contains a Substring in Python - Analytics Vidhya
January 10, 2024 - To check if a string contains multiple ... ... string = "Hello, World!" substrings = ["Hello", "Python"] if all(substring in string for substring in substrings): print("All substrings found!") else: print("One or more substrings not found.")...