Python String startswith() Method Tutorial

In this section we will learn what String startswith() method is and how to use it in Python.

What is String startswith() Method in Python?

The Python string startswith() method is used to see if a string value starts with a specific value or not.

Python String startswith() Method Syntax:

string.startswith(value, start, end)

String startswith() Method Parameter

The method takes 3 arguments:

  • The first argument is the value we want to check the target string to see if it starts with that value or not.
  • The second argument is the start position of the target string value. Note that this value is optional and if ignored, the value 0 will be used instead.
  • The third and the last argument is used to declare at which position the search should stop. This value is also optional and if ignored, the size of the target string value will be used instead.

String startswith() Method Return Value

The return value of this method is of type boolean and will be true if the target string starts with the specified value. Otherwise, the value false will return instead.

Example: using python string startswith() method

s1 = "Hello World 123!"

result = s1.startswith("hello")




Note that here we got the value false even though the argument of the method was “hello”! This is because of the first character “h” which is lowercase, however, the target string value starts with the uppercase “H” instead.

This means the `startswith()` method is case-sensitive!

Leave a Reply