This post will discuss how to check if a string starts with a specific string in Python.

1. Using str.startswith() function

The preferred, fast way to check if the string starts with the given prefix uses the str.startswith() function.

Download  Run Code

 
The str.startswith() function can also accept a tuple of prefixes. This is useful when you want to match multiple prefixes with the string.

Download  Run Code

2. Using Regex

Another approach is to use the regex, but using a regex match for this trivial task would be overkill. This is demonstrated below in Python:

Download  Run Code

That’s all about determining whether a string starts with a specific string in Python.