str.startswith允许您提供一个字符串元组来测试:
if link.lower().startswith(("js", "catalog", "script", "katalog")):从文档:
str.startswith(prefix[, start[, end]])返回
True如果字符串开始用prefix,否则返回False。prefix也可以是要查找的前缀的元组。
下面是一个演示:
>>> "abcde".startswith(("xyz", "abc"))True>>> prefixes = ["xyz", "abc"]>>> "abcde".startswith(tuple(prefixes)) # You must use a tuple thoughTrue>>>


