Home / Python / Reference / String methods

Python string startswith() method

Check whether a string starts with some text.

Syntax

str.startswith(prefix)

Give a tuple to check several possible prefixes at once.

Parameters

prefixa string, or a tuple of strings

Return value

bool

Example

Code

print("Brisbane".startswith("Bris"))
url = "https://softmaxima.com"
print(url.startswith(("http://", "https://")))

Output

True
True

Related

Learn it step by step in the free lesson Strings, with exercises that check your answers.