>>> x = "Hello World!"
>>> x[2:]
'llo World!'
>>> x[:2]
'He'
>>> x[:-2]
'Hello Worl'
>>> x[-2:]
'd!'
>>> x[2:-2]
'llo Worl'

Python calls this concept "slicing" and it works on more than just strings. Take a look here for a comprehensive introduction.

Answer from Paolo Bergantino on Stack Overflow
🌐
W3Schools
w3schools.com › python › python_strings.asp
Python Strings
W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.
🌐
Codecademy
codecademy.com › docs › python › substrings
Python | Substrings | Codecademy
June 18, 2025 - A Python substring is a sequence of characters that are part of an original string. In Python, substrings can be obtained by using the slicing feature on a string variable.
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-substring-a-string-in-python
How to Substring a String in Python - GeeksforGeeks
July 23, 2025 - In this example, we are trying to extract the starting word from the string.we used string slicing to extract the substring "Geeks" from the beginning of the string.
🌐
Sentry
sentry.io › sentry answers › python › extract a substring from a string in python
Python Substring Extraction With Slice Notation | Sentry
3 weeks ago - Extract substrings from Python strings using slice notation with [start:end] indexes, or use re.search() with regex patterns for matching specific formats
🌐
Real Python
realpython.com › python-string-contains-substring
How to Check if a Python String Contains a Substring – Real Python
December 1, 2024 - The in operator is intuitive and readable, making it a straightforward way to evaluate substring existence. By the end of this tutorial, you’ll understand that: The in membership operator is the recommended way to check if a Python string contains a substring.
Find elsewhere
🌐
Medium
medium.com › nerd-for-tech › python-substrings-everything-you-need-to-know-4cca526c07eb
Python Substrings: Everything You Need to Know | Nerd For Tech
July 21, 2021 - You can also define substring as a sequence of characters within a string. From the previous example, python substrings can be “Friday”, “at”, “meet”, and others.
🌐
Built In
builtin.com › software-engineering-perspectives › python-substring-indexof
5 Ways to Find the Index of a Substring in Python | Built In
A string in Python can be sliced using the slice() method. You can specify which index value in the string to begin slicing, which index to end slicing and how many steps to slice at (if wanting to skip every other character, etc.). The result will return the characters in a string based on the slice specifications. Substrings can be fetched from a larger string in Python using the slice() method.
🌐
Udemy
blog.udemy.com › home › it & development › software development › substrings in python and the many ways you can use them
Substrings in Python and Ways You Can Use Them - Udemy Blog
April 14, 2026 - This article will introduce you ... If a string is a sequence of characters, a Python substring is simply a sequence of characters within another string....
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-string-find
Python String find() Method - GeeksforGeeks
April 26, 2025 - find() method in Python returns the index of the first occurrence of a substring within a given string. If the substring is not found, it returns -1. This method is case-sensitive, which means "abc" is treated differently from "ABC".
🌐
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. If start is not in...
🌐
YouTube
youtube.com › watch
Identifying a Substring Within a Python String - YouTube
If you’re new to programming or come from a programming language other than Python, you may be looking for the best way to check whether a string contains an...
Published   April 6, 2023
🌐
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?

🌐
HackerNoon
hackernoon.com › python-substrings-everything-you-need-to-know-031537pa
Python Substrings: Everything You Need to Know | HackerNoon
June 29, 2021 - A python substring is a sequence of characters within a string, in this article you will learn various operations related to them and how to use them.
🌐
GeeksforGeeks
geeksforgeeks.org › python › find-the-index-of-a-substring-in-python
Find the Index of a Substring in Python - GeeksforGeeks
July 23, 2025 - The substring 'for' is found at index 6. The re.search() in Python's re module can be used to locate the first occurrence of a pattern in a string.
🌐
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. …
🌐
Python
docs.python.org › 3 › library › string.html
string — Common string operations
Template strings provide simpler string substitutions as described in PEP 292. A primary use case for template strings is for internationalization (i18n) since in that context, the simpler syntax and functionality makes it easier to translate than other built-in string formatting facilities in Python.
🌐
IONOS
ionos.com › digital guide › websites › web development › python substring
How to create and edit Python substrings
July 19, 2023 - In Python, there are different ways to create sub­strings or to check for sub­strings within a string. A substring is es­sen­tial­ly just a portion of a Python string, with a string being a sequence of char­ac­ters of any length.
🌐
Better Stack
betterstack.com › community › questions › how-to-get-substring-in-python
How do I get a substring of a string in Python? | Better Stack Community
January 26, 2023 - To get a substring of a string in Python, you can use the string slicing notation, which is string[start:end], where start is the index of the first character of the substring, and end is the index of the character just after the last character ...
🌐
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
Here's our challenge: we have two lists of strings of the same length, one containing the "original" strings and the other, the "substrings". We're to identify all occurrences of each substring within its corresponding original string and return a list of the starting indices of these occurrences.