Python startswith list must use a tuple though
Check if a string starts with any element in the list in Python
Python example code use str.startswith() to find it a string starts with some string in a list.
In the example list of substrings has converted into a tuple using tuple(list) in order to return a boolean if str contains substrings found it.
search = ["Hello", "Hi", "Hey"] string = "Hey World!" print(string.startswith(tuple(search)))
print("abcde".startswith(("xyz", "abc"))) prefixes = ["xyz", "abc"] print("abcde".startswith(tuple(prefixes)))
Do comment if you have any doubts and suggestions on this python list topic.
Note: IDE: PyCharm 2021.3.3 (Community Edition)
All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.
Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology & like learning technical.