Python | The line starts with ()

Python Methods and Functions

Syntax :

  str.startswith (prefix, start, end)  

Parameters:

  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 no start and end indices are specified, then it defaults to 0 and length-1 as the start and end indices, where end indices are not included in our search.

Returns :

 It returns True if strings starts with the given prefix otherwise returns False. 

Examples :

 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 occurs when the argument string is not found in the target string

# Python code shows working
Function # .startsswith ()

 

text = "geeks for geeks."

 
# returns False

result = text. startswith ( 'for geeks' )

print (result)

 
# returns True

result = text.startswith ( 'geeks' )

print (result)

 
# returns False

result = text.startswith ( 'for geeks.' )

print (result)

 
# returns True

result = text.startswith ( 'geeks for geeks.' )

print (result)

Output:

 False True False True