我有这样的 idea :
extensionsToCheck = ['.pdf', '.doc', '.xls']
for extension in extensionsToCheck:
if extension in url_string:
print(url_string)
我想知道在Python中实现这一点(不使用for循环)的更优雅的方法是什么?我曾想过这样的事情(比如从C/C++),但没有成功:
if ('.pdf' or '.doc' or '.xls') in url_string:
print(url_string)
Edit: I'm kinda forced to explain how this is different to the question below which is marked as potential duplicate (so it doesn't get closed I guess).
The difference is, I wanted to check if a string is part of some list of strings whereas the other question is checking whether a string from a list of strings is a substring of another string. Similar, but not quite the same and semantics matter when you're looking for an answer online IMHO. These two questions are actually looking to solve the opposite problem of one another. The solution for both turns out to be the same though.