Python String startswith() Method
The Python startswith() method is used to check if a string starts with a specified value. It returns True if the string starts with the value, otherwise False.
For example:
text = "Hello, welcome to my world."
result = text.startswith("Hello")
print(result)
# Output: True
You can also pass optional parameters start and end to the startswith() method. They specify the start and end positions of the string where the check is performed.
For example:
text = "Hello, welcome to my world."
result = text.startswith("wel", 7, 20)
print(result)
# Output: True
If you have any questions about this code, you can drop a line in comment.
Comments
Post a Comment