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 operator.contains() function checks for substring presence in a string programmatically. It provides the same result as the in operator but belongs to Python’s operator module, making it useful in functional programming contexts.
🌐
Real Python
realpython.com › python-string-contains-substring
How to Check if a Python String Contains a Substring – Real Python
December 1, 2024 - Now that you can inspect all the substrings that Python identifies, you may notice that Python doesn’t care whether there are any characters after the substring "secret" or not. It finds the word whether it’s followed by whitespace or punctuation. It even finds words such as "secretly". That’s good to know, but what can you do if you want to place stricter conditions on your substring check? ... You may only want to match occurrences of your substring followed by punctuation, or identify words that contain the substring plus other letters, such as "secretly".
🌐
Note.nkmk.me
note.nkmk.me › home › python
String Comparison in Python (Exact/Partial Match, etc.) | note.nkmk.me
April 29, 2025 - x in y returns True if x is contained in y (i.e., x is a substring of y), and False if it is not. If the characters of x appear in y but not consecutively, False is returned. print('bbb' in 'aaa-bbb-ccc') # True print('xxx' in 'aaa-bbb-ccc') ...
🌐
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.
🌐
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 - Python provides two common ways to check if a string contains another string. The in operator is the most readable and idiomatic way to check if a substring exists in a string. It returns True or False directly. find() returns the index of the first match, or -1 if not found.
Find elsewhere
🌐
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?

🌐
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
Python makes it easy to check whether a string contains a specific substring, offering several tools to match a variety of use cases. If we’re looking for a quick and readable way to check for the presence of a substring in a string, the in operator is our best bet.
🌐
LearnDataSci
learndatasci.com › solutions › python-string-contains
Python String Contains – See if String Contains a Substring – LearnDataSci
Looking at the Match object, span gives us the start and end index for 'apples'. Slicing the string using 'This string has apples'[16:22] returns the substring 'apples'. The match field shows us the part of the string that was a match, which can be helpful when searching for a range of possible substrings that meet the search conditions.
🌐
Python Morsels
pythonmorsels.com › substring-check
Substrings in Python: checking if a string contains another string - Python Morsels
May 9, 2023 - In Python, we usually check for substrings using the in operator instead of the index or find methods.
🌐
W3Schools
w3schools.com › python › python_strings.asp
Python Strings
Python If Python Elif Python Else Shorthand If Logical Operators Nested If Pass Statement Code Challenge Python Match
🌐
Python documentation
docs.python.org › 3 › library › re.html
re — Regular expression operations
May 25, 2026 - Adjacent empty matches are not possible, but an empty match can occur immediately after a non-empty match. As a result, sub('x*', '-', 'abxd') returns '-a-b--d-' instead of '-a-b-d-'. In string-type repl arguments, in addition to the character escapes and backreferences described above, \g<name> will use the substring matched by the group named name, as defined by the (?P<name>...) syntax.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-get-matching-substrings-in-string
Python | Get matching substrings in string - GeeksforGeeks
March 24, 2023 - The original string is : GfG is good website The original list is : ['GfG', 'site', 'CS', 'Geeks', 'Tutorial'] The list of found substrings : ['GfG', 'site'] Method #3 : Using find() method. find() method returns the position of the string passed ...
🌐
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.
🌐
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. Here’s What We Know So Far. Data Center Moratoriums, Explained: Which States Are Pausing New AI Infrastructure? Forget Chrome. OpenAI’s Atlas Turns the Web Into ChatGPT’s Playground. Explore Job Matches...
🌐
FavTutor
favtutor.com › blogs › string-contains-substring-python
Check if Python string contains substring: 3 Methods (with code)
January 23, 2023 - You can use the .findall() function instead of .search() function to find every matching substring that ends with punctuation. Python has __contains__() as an instance method to check for substrings in a string.
🌐
CodeSignal
codesignal.com › learn › courses › practicing-string-operations-and-type-conversions-in-python › lessons › exploring-substring-search-in-python-strings
Exploring Substring Search in Python Strings
The following step is to locate ... of the 'substring' in the 'original'. We use a while loop to accomplish this. But, how will we know when to stop seeking more occurrences? Good question! The moment our .find() function begins returning -1, it signifies that there are no more matches to be ...
🌐
W3Schools
w3schools.com › PYTHON › python_match.asp
Python Match
month = 5 day = 4 match day: case 1 | 2 | 3 | 4 | 5 if month == 4: print("A weekday in April") case 1 | 2 | 3 | 4 | 5 if month == 5: print("A weekday in May") case _: print("No match") Try it Yourself » ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com · If you want to report an error, or if you want to make a suggestion, send us an e-mail: help@w3schools.com · HTML Tutorial CSS Tutorial JavaScript Tutorial How To Tutorial SQL Tutorial Python Tutorial W3.CSS Tutorial Bootstrap Tutorial PHP Tutorial Java Tutorial C++ Tutorial jQuery Tutorial
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-check-if-substring-is-part-of-list-of-strings
Python | Check if substring is part of List of Strings - GeeksforGeeks
May 3, 2023 - Method #2 : Using any() The any function can be used to compute the presence of the test substring in all the strings of the list and return True if it's found in any. This is better than the above function as it doesn't explicitly take space to create new concatenated string. ... # Python3 code to demonstrate working of # Check if substring is part of List of Strings # Using any() # initializing list test_list = ['GeeksforGeeks', 'is', 'Best'] # test string check_str = "for" # printing original string print("The original string is : " + str(test_list)) # Using any() # Check if substring is part of List of Strings res = any(check_str in sub for sub in test_list) # printing result print("Is check string part of any input list string : " + str(res))
🌐
Wikipedia
en.wikipedia.org › wiki › Regular_expression
Regular expression - Wikipedia
3 weeks ago - A regex processor translates a ... and matched against a string representing the text being searched in. One possible approach is the Thompson's construction algorithm to construct a nondeterministic finite automaton (NFA), which is then made deterministic and the resulting deterministic finite automaton (DFA) is run on the target text string to recognize substrings that match ...