Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
List basics
Lists with if statements and loops
11. The in operator
Lists in functions
Summary

Instruction

Great. Lists in Python work great with if statements. Suppose we want to check if a value is present in the list:

# define a list
companies = ...
# check if AXA is there
if 'AXA' in companies:
  print('AXA found')
else:
  print('AXA not found')

We used the in operator to check if 'AXA' is present in companies. You can also use the not in operator to check if an item is missing.

Exercise

You are given a list of 12 values in a variable named tourist_arrivals. The values represent the number of tourists (in millions) that visited France in each month of 2016.

Write a program that will ask the user for a number and will check if there is any month whose value is exactly this number. If there is such a month, print:

Value found.

Otherwise, print:

Value not found.

Stuck? Here's a hint!

Use the following construction:

if number in tourist_arrivals:
  # do something
else:
  # do something else