strstartswith
Strstartswith is a method of Python's built-in string type used to determine whether a string begins with a specified prefix. It is called on a string object as s.startswith(prefix, start, end) and returns a boolean value. The method accepts a single string prefix or a tuple of strings as the prefix argument. If a tuple is provided, the method returns True if the string starts with any of the elements in the tuple.
Parameters and behavior: prefix is required and can be a string or a tuple of strings. Start
Tuple handling: When a tuple of prefixes is given, every element must be a string. The method
Performance and usage: str.startswith is implemented in C and is generally efficient for simple prefix checks.
- "hello world".startswith("hello") -> True
- "https://example.com".startswith("http://", "https://") -> True
- "http://example.com".startswith("https://", 0, 5) -> False
See also: endswith for suffix checks, and the broader family of string matching methods in Python.