String in Python has built-in functions for almost every action to be performed on a string. Python String startswith() function checks for the specific prefix in a string and returns True else False.
- Return Type: Boolean i.e. True or False
- Parametric Values: There are 3 parameters: Prefix, Start, End
|Prefix||It can be a String or Tuple of Strings that are to be checked. It is|
|Start||It is optional and is to specify the starting index from where the check will start|
|End||It is optional and is to specify the ending index where the check will end|
Python String startswith() Syntax
str_name here refers to the string in which prefix is to be checked and strartwith() is an inbuilt function.
String startswith() Examples
text_string = "Engineering and Management are altogether diferent verticals." resultant = text_string.startswith('Engineering') print(resultant) resultant = text_string.startswith('Management ') print(resultant)
text_string = "Engineering and Management are altogether different verticals." resultant = text_string.startswith('Engineering',0) print(resultant) resultant = text_string.startswith('Management',16,60) print(resultant)
str = "Engineering Discipline" string=str.startswith("Discipline") print (string)
In this article, we have understood the working and implementation of substring() function under various circumstances of inputs.