Answers for "python string starts with any char of list"

0

python string starts with any char of list

# `str.startswith` supports checking for multiple prefixes:
>>> "abcde".startswith(("xyz", "abc"))
True
# You must use a tuple though, so convert your lists using tuple()
>>> prefixes = ["xyz", "abc"]
>>> "abcde".startswith(tuple(prefixes))
True
Posted by: Guest on February-04-2021

Python Answers by Framework

Browse Popular Code Answers by Language