Python3 startswith () method
description
startswith () method is used to check whether the string is specified at the beginning of the substring, if it returns True, otherwise False. If the argument beg and end the specified value, check within the specified range.
grammar
startswith () method syntax:
str.startswith(str, beg=0,end=len(string));
parameter
- str - string detected.
- strbeg - optional parameter is used to set the starting position of the string detection.
- strend - optional parameter is used to set the string end position detection.
return value
If it is detected string is returned True, otherwise False.
Examples
The following example shows startswith () function to use:
#!/usr/bin/python3 str = "this is string example....wow!!!" print (str.startswith( 'this' )) print (str.startswith( 'string', 8 )) print (str.startswith( 'this', 2, 4 ))
Examples of the above output results are as follows:
True True False