str.startswith() Starts with prefix
Last updated: 2026-09-22
str.startswith() Starts with prefix
str.startswith(prefix[, start[, end]]) checks if the string starts with prefix.
| Category | String Methods |
|---|---|
| Kind | Built-in Type Method |
| Python Version | all |
📝 Syntax
str.startswith(prefix[, start[, end]])
⚙️ Parameters
| prefix Required | The prefix to check; a string or a tuple of strings. |
|---|---|
| start Optional | Start index of the range (inclusive); None means the beginning.(Default:None) |
| end Optional | End index of the range (exclusive); None means the end.(Default:None) |
Returns:bool. True if the string starts with prefix within the range.
Mutates the original:No (returns a new object)
▶ Example
Edit the code, press Run, and see the result in the output panel:
Output:
True
False
💡 Related Cases
More case studies coming soon — check back later.
❓ FAQ
QHow do I check multiple prefixes?
APass a tuple: 'hello.py'.startswith(('a', 'he')) returns True. prefix can be a string or a tuple of strings.
QIs it case-sensitive?
AYes. 'Http'.startswith('http') is False; you can lower() first.
QHow are start/end parameters used?
AThey delimit the inspection range (left-closed, right-open): 'hello'.startswith('el', 1) inspects the substring 'ello' starting at index 1 and returns True.