The startswith() method in Python checks if the string begins with str, optionally putting a restriction on the matching with the provided indices start and end. The startswith() method in Python returns a boolean. It also returns True in case the string begins with the specified prefix. It might return False when the string doesn't begin with the specified prefix.
Here is the syntax for startswith() method:
str.startswith(str, beg=0,end=len(string));
This method in Python string returns true if in case it is found matching with the string otherwise false.
The following example below shows the usage of startswith() method.
#!/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 )
When we run above program, it produces following result:
True True False
Here at Intellinuts, we have created a complete Python tutorial for Beginners to get started in Python.