Python Function Reference

str.startswith

Check whether the string starts with the given prefix.

Python 3.13
str.startswith(prefix[, start[, end]])

Parameters

prefixstr | tuple
The expected beginning of the string; with a tuple, any of the options matches.
startintoptional
The index where the check starts.
endintoptional
The index before which the check stops.

Return value

True or False.

Examples

Checking the start of a string

Python 3.13
print('hello'.startswith('he'))
True

Checking several options

Python 3.13
print('https://example.com'.startswith(('http://', 'https://')))
True

Details

Pass several options as a tuple: a list raises TypeError. The check is case-sensitive; to ignore case, convert the string to lowercase first. An empty prefix matches any string.

See also

Where to learn