The StartsWith () method checks whether a string starts with STR, and optionally restricts the start and end of the given index.
Grammar
The following is the syntax for the StartsWith () method:
Str.startswith (str, Beg=0,end=len (string));
Parameters
- STR-This is the string to check.
- Beg-This is the initial index of the optional parameter set matching boundary.
- End-This is an optional parameter to set the ending index of the matching boundary.
return value
If a matching string is found, this method returns True, otherwise false.
Example
The following example shows the use of the StartsWith () method.
#!/usr/bin/pythonstr = "This is string Example....wow!!!"; Print Str.startswith (' this ');p rint str.startswith (' was ', 2, 4);p rint str.startswith (' This ', 2, 4);
When we run the above program, it produces the following results:
Truetruefalse