Editor settings

General settings

Save settings

Learn to program with Python

Use in keyword with lists #

The in keyword can also be used to check if an item is present in a list.

For example:

fruits = ['apple', 'banana', 'cherry', 'date', 'elderberry']
print("apple" in fruits) # output: True
print("grape" in fruits) # output: False

Exercise #

  • Check if the list programming_languages contains the item "English" and assign it to the variable has_english.
  • Check if the list programming_languages contains the item "JavaScript" and assign it to the variable has_javascript.

Tests #

  • Variable has_english should be False
  • Variable has_javascript should be True
Output will be displayed here