Python Tutorial Python Advanced Python Resources Python Libraries
Python Java C++ C C# PHP R SQL DS Algo InterviewQ

Python - String startswith() Method



The Python String startswith() method is used to check whether the string starts with specified value or not. It returns true when the string starts with the specified value, else returns false.

Syntax

string.startswith(value, start, end)

Parameters

value Required. value to check whether the string starts with or not.
start Optional. integer specifying start position of search. default value is start of string.
end Optional. integer number specifying end position of search. default value is end of string.

Return Value

Returns True if the string starts with the specified value, else returns False.

Example:

In the example below, startswith() method is used to check whether the string (or a given section of the string) starts with specified value or not.

MyString = "Hello World!"
print(MyString.startswith("Hello"))

print(MyString.startswith("Hello", 0, 5))

The output of the above code will be:

True
True

❮ Python String Methods

5