Python in the operator is used to check if a value exists in a group of values (string, list, tuple, etc). The in operator returns True if an element is found. It returns False if not.
Python in operator
A simple example code check specified value is inside the sequence.
list1 = [1, 2, 3, 4, 5] print(5 in list1) # True s = "A is A" print("is" in s) # True tuple1 = (11, 22, 33, 44) print(88 in tuple1) # False
Let’s see the in operator in the if..else condition.
s = "Game of Thrones was the good show" if "Thrones" in s: print('It exists') else: print('Does not exist')
Output: It exists
Note: Python not in operator work opposite of in operator.
Do comment if you have any doubts or suggestions on this Python operator topic.
Note: IDE: PyCharm 2021.3.3 (Community Edition)
All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.
Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology & like learning technical.