Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

startswith
python

What is the startswith( ) method in Python?

Educative Answers Team

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

The startswith() method tells whether a certain string A starts with a string B.

svg viewer
Returns a boolean value
string_A = "What do i begin with?"
string_B = "What"
print ( string_A.startswith(string_B) ) # startswith() call
Make sure to play around with the strings

Optionally, you can add 2 more arguments. This gives you the power to see whether a very specific part within a string A starts with a string B.

These arguments are the starting and ending indices of this “specific part”.

svg viewer
string_A = "What do i begin with?"
string_B = "at"
print ( string_A.startswith(string_B, 2, 6) ) #startswith() call
Note that the starting index is inclusive while the ending index is exclusive

RELATED TAGS

startswith
python
Copyright ©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring