.startsWith()
The .startsWith()
Python string method checks whether a string begins with the specified characters. It will only return a boolean value, either true
or false
.
Syntax
string.startsWith(substring, position);
- The
substring
is the specified characters. - The
position
is optional. It is used to start searching forsubstring
. It starts at 0.
Example 1
Checking if a string starts with specified characters:
console.log('Do you prefer coffee or tea?'.startsWith('Do'));// Output: true
Example 2
Checking if a string starts with specified characters with a specified position:
console.log('Do you prefer coffee or tea?'.startsWith('coffee', 14));// Output: true
Contributors
- Anonymous contributors