python check if string contains any substring from list code example
Example 1: if list item in string python
if any(ext in url_string for ext in extensionsToCheck):
print(url_string)
Example 2: check if list contains string python
some_list = ['abc-123', 'def-456', 'ghi-789', 'abc-456']
if any("abc" in s for s in some_list):
Example 3: python check if string contains substring
string = "My favourite programming language is Python"
substring = "Python"
if substring in string:
print("Python is my favorite language")
elif substring not in string:
print("Python is not my favourite language")