Python Glossary Русский

all Python 3Strings (str)function

str.startswith

search

True if the string starts with the prefix (or one of a tuple of prefixes).

Syntax

s.startswith(prefix[, start[, end]])

The prefix must be a str or a tuple of str — a list or a set raises TypeError, which is the usual stumble. An empty prefix always matches. Passing start shifts the check to that position: s.startswith(p, 5) means the same as s[5:].startswith(p), but without copying the string.

Examples

print('hello'.startswith('he'))          # → True
print('hello'.startswith('lo'))          # → False
print('hello'.startswith(('hi', 'he')))  # → True

See also

Open in the full glossarydocs.python.orgReport an inaccuracy