Use the in operator:

if "blah" not in somestring: 
    continue

Note: This is case-sensitive.

Answer from Michael Mrozek on Stack Overflow
๐ŸŒ
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.
๐ŸŒ
Real Python
realpython.com โ€บ python-string-contains-substring
How to Check if a Python String Contains a Substring โ€“ Real Python
December 1, 2024 - Note: Python considers empty strings always as a substring of any other string, so checking for the empty string in a string returns True: ... This may be surprising because Python considers emtpy strings as false, but itโ€™s an edge case that is helpful to keep in mind.
๐ŸŒ
Codecademy
codecademy.com โ€บ docs โ€บ python โ€บ substrings
Python | Substrings | Codecademy
June 18, 2025 - A substring in Python is a contiguous sequence of characters extracted from an original string.
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_strings.asp
Python Strings
However, Python does not have a character data type, a single character is simply a string with a length of 1.
๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ tutorials โ€บ python-check-if-string-contains-another-string
How To Check If a String Contains Another String in Python | DigitalOcean
April 9, 2026 - The in operator returns True if the substring is found, while the find() method returns the index of the first occurrence of the substring, or -1 if itโ€™s not found. Regular expressions offer more advanced pattern matching and can be used for complex substring checks. text = "Learning Python is fun!" substring = "Python" if substring in text: print(f'"{text}" contains "{substring}"') else: print(f'"{text}" does not contain "{substring}"')
Find elsewhere
๐ŸŒ
Better Stack
betterstack.com โ€บ community โ€บ questions โ€บ how-to-check-if-string-contains-substring-in-python
How to check if a string contains a substring in Python? | Better Stack Community
January 26, 2023 - string = 'BetterStack' substring = 'Stack' if string.find(substring) != -1: print('Found it!') else: print('Not found!') ... This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. Difference between static and class methods in Python?
๐ŸŒ
LearnDataSci
learndatasci.com โ€บ solutions โ€บ python-string-contains
Python String Contains โ€“ See if String Contains a Substring โ€“ LearnDataSci
An easy way to check if a string contains a particular phrase is by using an if ... in statement. We can do this as follows: if 'apples' in 'This string has apples': print('Apples in string') else: print('Apples not in string') ... Today we'll take a look at the various options you've got for ...
๐ŸŒ
Built In
builtin.com โ€บ software-engineering-perspectives โ€บ python-substring-indexof
5 Ways to Find the Index of a Substring in Python | Built In
Substrings can be fetched from a larger string in Python using the slice() method. For example, if you want to fetch the substring 'pine' from the string 'pineapple', you could use slice() as follows: ... OpenAI Is Building a New Device.
๐ŸŒ
Bacancy Technology
bacancytechnology.com โ€บ qanda โ€บ python โ€บ python-string-contains
How does Python string contains substring method?
In python string contains: you can check whether a string contains a substring using the in keyword or the str.find() method.
๐ŸŒ
Server Academy
serveracademy.com โ€บ blog โ€บ python-substring-tutorial
Python Substring Tutorial Blog | Server Academy
July 10, 2024 - Manipulating Python strings is a common task you'll need to do regularly. One key skill is working with substrings, which are smaller parts of a larger stringโ€ฆ
๐ŸŒ
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
The .index() method is an inbuilt method in Python that allows us to search for a substring within a string. If the substring exists, the method returns the position or index of the first occurrence of the substring.
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ how-to-substring-a-string-in-python
How to Substring a String in Python
January 3, 2020 - Python offers many ways to substring a string. This is often called "slicing". Here is the syntax: string[start:end:step] Where, start: The starting index of the substring. The character at this index is included in the substring.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ what is the most efficient way to find substrings in strings?
r/learnpython on Reddit: What is the most efficient way to find substrings in strings?
January 11, 2022 -

Hello,

There are several ways to find substrings in string, You could use substring in string you could use string.index(substring), or you could use string.find(substring) or even use regex.

I'm trying to understand if there is a significant difference between them for my use case, which is finding people names in article titles for example:

I want to check if Leonardo DiCaprio is in Leonardo DiCaprio gets called out for boarding superyacht: โ€˜eco-hypocriteโ€™

What I usually do is:

def is_substring_in_string(substring: str, string: str):        
    #same thing as before but on the article title.
    string_alphanumeric = ''.join(e for e in string if e.isalnum()).lower()

    return substring in string_alphanumeric

def main():
    names = ["Harrison Ford","Leonardo DiCaprio","Eddie Murphy","Bruce Willis","Will Smith"]

    #removes unwanted charecters such as !@#$%^&*() etc and converts to lower case
    names_alnum_lower = [''.join(e for e in x if e.isalnum()).lower() for x in names]

    article_title = "Leonardo DiCaprio gets called out for boarding superyacht: eco-hypocrite"

    for idx, lower_name in enumerate(names_alnum_lower):
        if is_substring_in_string(lower_name,article_title):
            print(f"Actor Name: '{names[idx]}' is in article title '{article_title}'")

if __name__ == '__main__':
    main()

Imagine there are a bunch of articles and people's names. Is this method acceptable or will I be better off using regex or something else?

๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ how-to-substring-a-string-in-python
How to Substring a String in Python - GeeksforGeeks
July 23, 2025 - A String is a collection of characters arranged in a particular order. A portion of a string is known as a substring. For instance, suppose we have the string "GeeksForGeeks". In that case, some of its substrings are "Geeks", "For", "eeks", ...
๐ŸŒ
Stack Abuse
stackabuse.com โ€บ python-check-if-string-contains-substring
Python: Check if String Contains Substring
June 20, 2023 - The easiest way to check if a Python string contains a substring is to use the in operator.
๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ tutorials โ€บ python-string-substring
Python String Substring | DigitalOcean
August 4, 2022 - A substring is the part of a string. Python string provides various methods to create a substring, check if it contains a substring, index of substring etc. โ€ฆ
๐ŸŒ
Flexiple
flexiple.com โ€บ python โ€บ python-string-contains
Methods to check if a python string contains a substring - Flexiple Tutorials - Flexiple
March 10, 2022 - Another common use is to find the index of the substring in the string. It is most likely that you have come across the contains function in other programming languages. Python also supports the __contains__ method. It also supports a few faster and more readable methods to check if a python string contains a substring.
๐ŸŒ
Metaschool
metaschool.so โ€บ home โ€บ software development โ€บ master string searches in python 2025
Master String Searches in Python 2025
February 7, 2025 - In Python, you can determine if a string contains a particular substring by using the in keyword. Letโ€™s understand how to implement in using a coding example. text = "Hello, world!" substring = "world" if substring <strong>in</strong> text: ...
๐ŸŒ
Data Science Dojo
discuss.datasciencedojo.com โ€บ python
How to check if a string contains a substring in Python? - Python - Data Science Dojo Discussions
April 26, 2023 - I am working on a Python project, and I need to check if a string contains a specific substring. Does Python have a built-in method to check for the existence of substrings in a string? If not, whatโ€™s the most efficient โ€ฆ