The Python “in” operator checks if an element is present in a sequence or if a substring exists in a string. The “in” b returns True if the element or substring is found; otherwise, it returns False. The “in” operator can be used with various data structures, such as lists, strings, tuples, sets, and dictionaries (when checking for keys).
strA = "Game of Thrones was the best show on the planet" print("Thrones" in strA)
As you can see, an “in operator” returns the True value when the substring exists in the string. Otherwise, it returns false. The above approach is very straightforward, clean, readable, and conversational.
Let’s see the in operator in the if..else condition.
strA = "Game of Thrones was the best show on the planet" if "Thrones" in strA: print('It exists') else: print('Does not exist')