Easy Tutorial
❮ Python Func Eval Python String Split ❯

Python3 startswith() Method

Python3 Strings


Description

The startswith() method is used to check if a string starts with a specified substring. It returns True if the string starts with the specified substring, otherwise it returns False. If the parameters beg and end are specified, it checks within the specified range.

Syntax

The syntax for the startswith() method is:

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

Parameters

Return Value

Returns True if the string is found, otherwise returns False.

Example

The following example demonstrates the use of the startswith() function:

React Example

#!/usr/bin/python3

str = "this is string example....wow!!!"
print (str.startswith( 'this' ))   # Check if the string starts with 'this'
print (str.startswith( 'string', 8 ))  # Check if the string starting from the 9th character starts with 'string'
print (str.startswith( 'this', 2, 4 )) # Check if the string from the 2nd to the 4th character starts with 'this'

The output for the above example is:

True
True
False

Python3 Strings

❮ Python Func Eval Python String Split ❯