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
| Name | Description |
|---|---|
| prefix | Text, or a tuple of text choices, to look for at the start. |
| start | Optional starting position. |
| end | Optional 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://')).