Python String startswith() Method
Example
Check if the string starts with "Hello":
txt = "Hello, welcome to my world." x = txt.startswith("Hello") print(x)
Definition and Usage
If the string starts with the specified value, the startswith() method returns True, otherwise it returns False.
Syntax
string.startswith(value, start, end)
Parameter Value
Parameter | Description |
---|---|
value | Required. Check if the string starts with the specified value. |
start | Optional. Integer, specifies the starting position for the search. |
end | Optional. Integer, specifies the position to end the search. |
More Examples
Example
Check if the position 7 to 20 starts with the character "wel":
txt = "Hello, welcome to my world." x = txt.startswith("wel", 7, 20) print(x)