Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python startswith() method

Python startswith() method

Python Strings Python Strings


Description

The Python startswith() method checks whether a string starts with the specified substring, returning True if it does and False otherwise. If the parameters beg and end are specified, the check is performed within that range.

Syntax

Syntax of the startswith() method:


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

Parameters

Return Value

Returns True if the string is detected, otherwise False.

Example

The following example shows how to use the startswith() function:


#!/usr/bin/python

str = "this is string example....wow!!!";
print str.startswith( 'this' );
print str.startswith( 'is', 2, 4 );
print str.startswith( 'this', 2, 4 );

The output of the above example is:


True
True
False

Python Strings Python Strings