Latest Code Tutorials

Python String Startswith: How to Check Start Character of String

To find a string that starts with something(prefix), use the Python String startswith() function.

Python String startswith()

Python string startswith() is an inbuilt function that checks whether the string starts with a given prefix otherwise it returns False. It optionally restricting the matching with the given indices start and end. Python String startswith() returns true if found matching string otherwise false.


str.startswith(prefix, beg=0,end=len(string));


  1. prefix − This is the string to be checked.
  2. beg − This is the optional parameter to set a start index of the matching boundary.
  3. end − This is the optional parameter to end start index of the matching limit.

Let’s see the example.


strA = 'Hello AppDividend'
print(strA.startswith('App', 6))

In the above code, we have checked for the prefix called App which is starting from a 6th index in the strA string.

So, the output will be true.

Here, one thing to note that the prefix is case sensitive. So, if you find an app, then it will give the false output. It will only give true if the substring is App and it starts with the 6th index.

See the output.

Python String Startswith Example

Let’s see the following scenario.


strA = 'Hello AppDividend'
print(strA.startswith('app', 6))

Here, we are checking for the app and not App. So the startswith() function is case sensitive; that is why It will give us the false in the output.

Python startswith() Tutorial

So, the startswith() method returns True if a string starts with the specified prefix(string). If not, it returns False.

Finally, Python String startswith() Example is over.

Leave A Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.