String Methods
str.startswith()
Test whether the bounded text begins with the specified prefix. Accept a string or a tuple of candidate strings, testing until a match is found. Matching is exact and case-sensitive, not a regular expression. Empty candidates match valid boundaries; a tuple with no candidates fails. The original string is unchanged.
Formal Syntax & Structure
python syntaxpython
text.startswith(prefix[, start[, end]])Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| prefix | str | tuple[str, ...] | One literal candidate or tuple of alternatives. |
| start | int | None | Optional inclusive start bound; negative values are relative to the end. |
| end | int | None | Optional exclusive end bound; defaults to the end. |
Return Value
bool
True if any candidate matches the requested boundary; otherwise False.
Working Example
Example Snippetpython
filename = "api.json"print(filename.startswith('api'))print(filename.startswith(('api', "other")))print(filename.startswith('.json'))