The startswith() method in Python is a String Method that checks if a string starts with the specified prefix. It returns True if the string starts with the specified prefix, otherwise it returns False.
Parameter Values
| Parameter | Description |
|---|---|
| prefix | The |
| start | The |
| end | The |
Return Values
The startswith() method in Python returns a bool (True or False).
How to Use startswith() in Python
The startswith() method checks if a string starts with a specified substring. It returns True if the string starts with the given substring, otherwise False.
text = 'Hello, World!'
print(text.startswith('Hello'))The method is case-sensitive, so 'H' is not the same as 'h'.
text = 'Hello, World!'
print(text.startswith('hello'))You can specify the starting index within the string where the checking should begin.
text = 'Hello, World!'
print(text.startswith('World', 7)