Facebook Page Twitter Page LinkedIn Page
× Python Tutorial Python Advanced Python Resources Python Libraries


The Python in keyword is a membership operator which validates membership of element in the sequence like list, tuple, set, dictionary etc. It returns true when the element is present in the sequence, otherwise it returns false.

Syntax

(element in sequence)          

Example:

In the below example, in keyword is used to check the membership of variable x in the given list called days.

days = ['MON','TUE','WED','THU','FRI']
x = 'SUN'
if x in days:
  print('yes,', x ,'is present in the list.')
else:
  print('No,', x ,'is not present in the list.')

The output of the above code will be:

No, SUN is not present in the list.

Example 2:

In the below example, in keyword is used to print all members of the given list called days.

days = ['MON','TUE','WED','THU','FRI']
for x in days:
  print(x)

The output of the above code will be:

MON
TUE
WED
THU
FRI

❮ Python Keywords