0
Python - Check if there are some word inside a sting
I want to check if a string contains one or more specific words inside it. Normally i will do this: If "hi" in str or "hello" in str: print('true') Any way to make it smaller? I have tried to do this but it wont work If "hi", "hello" in str: print('true')
2 Antworten
+ 3
for greeting in long_list_of_greetings:
if greeting in string:
print('true')
+ 1
Add a break to Honfu's solution since you only want "True" to be printed once.
OR
if any(gretting in string for greeting in long_list_of greetings):
print("True")