Recommended Free Tools
Use Python’s built-in str.startswith() method. It returns True when a string begins with the given prefix and False otherwise.
Check for one prefix
Call startswith() on the string and pass the prefix you want to test:
text = "Python programming"
prefix = "Python"
if text.startswith(prefix):
print("The string starts with the prefix")
The method’s form is str.startswith(prefix[, start[, end]]). The comparison uses the text as provided, so it is case-sensitive: "Python" matches the beginning of "Python programming", but not "python programming". Python’s built-in types documentation describes the method and its return value.
Check for one of several prefixes
Pass a tuple when any one of several complete prefixes should count as a match:
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
#1 Best Overall
url = "https://example.com"
if url.startswith(("http://", "https://")):
print("The URL uses a supported scheme")
Each tuple member is checked as a candidate prefix. A tuple is not a set of individual characters; for example, ("http://", "https://") tests those two full beginnings.
Check a prefix at a particular position
Use the optional start and end arguments to limit the comparison to a region of the string. For example, this checks whether "programming" begins at position 7:
Rank #2
text = "Python programming"
text.startswith("programming", 7) # True
The range arguments let you make the check without first creating a sliced string. The documentation establishes the range behavior; it does not establish a performance advantage.
Perform a caseless Unicode prefix check
startswith() does not ignore case automatically. For caseless Unicode matching, casefold both the string and the prefix before checking:
Free tools Windows power users keep installed
One-click scans. No signup required.
text = "Straße"
prefix = "STRASSE"
text.casefold().startswith(prefix.casefold()) # True
Python documents casefolded strings as useful for caseless matching. Casefolding is more aggressive than lowercasing; for example, "straße".lower() remains "straße", while "straße".casefold() becomes "strasse". See the Python documentation for str.casefold().
Remove a matching prefix instead of checking it
If you need the resulting string with a matching prefix removed, use removeprefix():
text = "TestHook"
text.removeprefix("Test") # "Hook"
If the prefix does not match, removeprefix() returns the original string. It was added in Python 3.9. Use startswith() when you only need a yes-or-no check. Python documents removeprefix() and its version history.
Check a prefix in binary data
bytes and bytearray also provide startswith(). Pass a bytes-like prefix, or use a tuple of prefixes and the optional range positions:
Best Value
data = b"Python data"
data.startswith(b"Python") # True
For these binary types, use a bytes-like prefix such as b"Python", rather than a text string. The Python documentation covers bytes and bytearray prefix checks.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




