Python startswith() method
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
- str -- the string to check.
- strbeg -- optional parameter that sets the starting position of the check.
- strend -- optional parameter that sets the ending position of the check.
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