Home >>Python String Methods >Python String startswith() Method

Python String startswith() Method

Python String startswith() Method

Python string startswith() method is used to return True if the string starts with the required value otherwise it will return False.

Syntax:
string.startswith(value, start, end)

Parameter Values

Parameter Description
value This is a required parameter. It defines the value to check if the string starts with.
start This is an optional parameter. It defines an Integer specifying at which position to start the search.
end This is an optional parameter. It defines an Integer specifying at which position to end the search.
Here is an example of Python startswith() method:

txt = "Hello, welcome to PHPTPOINT."
x = txt.startswith("Hello")
print(x)

Output:
True
Example 2:

txt = "Hello, welcome to PHPTPOINT."
x = txt.startswith("Hello", 5, 15)
print(x)

Output:
False

No Sidebar ads