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_languagescontains the item"English"and assign it to the variablehas_english. - Check if the list
programming_languagescontains the item"JavaScript"and assign it to the variablehas_javascript.
Tests #
- Variable
has_englishshould beFalse - Variable
has_javascriptshould beTrue
Getting Started with Python
Data Types
Python Functions
Statements in Python
Basic Debugging in Python
Basic Algorithm
Object-Oriented Programming
Error Handling
Intermediate Algorithm
Python Modules