Content-Length: 372818 | pFad | https://www.askpython.com/python/string/python-string-startswith-function

Python String startswith() Function - AskPython

Python String startswith() Function

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.

Key Points:

  • Return Type: Boolean i.e. True or False
  • Parametric Values: There are 3 parameters: Prefix, Start, End
PrefixIt can be a String or Tuple of Strings that are to be checked. It is
Case Sensitive
StartIt is optional and is to specify the starting index from where the check will start
EndIt is optional and is to specify the ending index where the check will end

Python String startswith() Syntax

str_name.startswith()

str_name here refers to the string in which prefix is to be checked and strartwith() is an inbuilt function.


String startswith() Examples

Example 1:

text_string = "Engineering and Management are altogether diferent verticals."

resultant = text_string.startswith('Engineering')

print(resultant)

resultant = text_string.startswith('Management ')

print(resultant)

Output :

Output Startswith Example1
Output-startswith() Example1

Example 2:

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)

Output:

Output Startswith Example2
Output-startswith() Example2

Example 3:

str = "Engineering Discipline"

string=str.startswith("Discipline")

print (string)

Output:

False

Conclusion

In this article, we have understood the working and implementation of substring() function under various circumstances of inputs.

References

Pankaj Kumar
Pankaj Kumar

I have been working on Python programming for more than 12 years. At AskPython, I share my learning on Python with other fellow developers.

Articles: 250








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://www.askpython.com/python/string/python-string-startswith-function

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy