The startswith() method returns True if a string starts with the given prefix otherwise returns False.
str.startswith(prefix, start, end)
prefix : prefix ix nothing but a string which needs to be checked. start : Starting position where prefix is needs to be checked within the string. end : Ending position where prefix is needs to be checked within the string.
NOTE : If start and end index is not provided then by default it takes 0 and length-1 as starting and ending indexes where ending indes is not included in our search.
It returns True if strings starts with the given prefix otherwise returns False.
Input : text = "geeks for geeks." result = text.startswith('for geeks') Output : False Input : text = "geeks for geeks." result = text.startswith('geeks', 0) Output : True
Error : ValueError : This error is raised in the case when the argument string is not found in the target string
False True False True
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.