1

With the startswith() and endswith() functions it is possible to pass a tuple of strings, where if there is a match on any element the result is returned True e.g.,:

text_to_find = ("string_1", "string2")

test = "string_to_look_in"

if test.startswith(text_to_find ) == True:
     print  ("starts with one of the strings")

Is there a similar command, that will work with tuples, for finding a string in a string - i.e., one of the strings in the tuples appearing anywhere in the text. (instead of e.g., using a for loop, where individually look each item in the string).

Ma0
  • 15,057
  • 4
  • 35
  • 65
kyrenia
  • 5,431
  • 9
  • 63
  • 93

1 Answers1

4

First of all, try using any to test all items in a list. Second, since you want to know if the string is contained anywhere in the text, you can use in. For example:

text_to_find = ("string_1", "string2", "to_look")

test = "string_to_look_in"

if any(s in test for s in text_to_find):
     print  ("contains one of the strings")
Kewl
  • 3,327
  • 5
  • 26
  • 45