Skip to content
String Methods

startswith()

Check whether text starts with a particular prefix.

str.startswith(prefix, start=0, end=len(str))

str.startswith() returns True if the string starts with the specified prefix; otherwise returns False.

Parameters

NameDescription
prefixText, or a tuple of text choices, to look for at the start.
startOptional starting position.
endOptional position where the check stops.

Returns

True or False.

Try it

Run it and change it
text = "Python"
print(text.startswith("Py"))

Worth knowing

  • Tuple of prefixes: You can pass a tuple of candidate prefixes: url.startswith(('https://', 'http://')).

Related entries