Python string startswith() method “returns True if a string starts with the specified prefix(string). If not, it returns False.”
Syntax
str.startswith(prefix, beg=0,end=len(string));
Parameters
- prefix − This is the string to be checked.
- beg − This is the optional parameter to set a start index of the matching boundary.
- end − This is the optional parameter to the end start index of the matching limit.
Return value
The startswith() method returns a boolean.
- It returns True if the string starts with the specified prefix.
- It returns False if the string doesn’t start with the specified prefix.
Example 1: How to Use startswith() Method
strA = 'Hello AppDividend'
print(strA.startswith('App', 6))
Output
Example 2: startswith() With start and end Parameters
strA = 'Hello AppDividend'
print(strA.startswith('app', 6, 10))
Output
Example 3: startswith() With Tuple Prefix
text = "Homer Simpson is funniest characters"
result = text.startswith(('Homer', 'characters'))
print(result)
result_2 = text.startswith(('Bart', 'is', 'funny', 'too'))
print(result_2)
result_3 = text.startswith(('homer', 'characters'), 10, 19)
print(result_3)
Output
True
False
False
That’s it.

Krunal Lathiya is a seasoned Computer Science expert with over eight years in the tech industry. He boasts deep knowledge in Data Science and Machine Learning. Versed in Python, JavaScript, PHP, R, and Golang. Skilled in frameworks like Angular and React and platforms such as Node.js. His expertise spans both front-end and back-end development. His proficiency in the Python language stands as a testament to his versatility and commitment to the craft.