0
0
Pythonprogramming~5 mins

List length and membership test in Python - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
How do you find the number of items in a list in Python?
Use the len() function. For example, len(my_list) returns the number of items in my_list.
Click to reveal answer
beginner
What does the expression item in my_list check?
It checks if item is present anywhere inside my_list. It returns True if found, otherwise False.
Click to reveal answer
beginner
What will len([]) return?
It returns 0 because the list is empty and has no items.
Click to reveal answer
beginner
How can you check if the number 5 is NOT in a list called numbers?
Use the expression 5 not in numbers. It returns True if 5 is not found in the list.
Click to reveal answer
beginner
What is the output of this code?
my_list = [1, 2, 3, 4]
print(len(my_list))
print(3 in my_list)
print(5 in my_list)
The output is:
4
True
False

Explanation:
- len(my_list) is 4 because there are 4 items.
- 3 in my_list is True because 3 is in the list.
- 5 in my_list is False because 5 is not in the list.
Click to reveal answer
What does len([10, 20, 30]) return?
A3
B30
C0
DError
Which expression checks if 'apple' is in the list fruits?
A'apple' not in fruits
Bfruits in 'apple'
C'apple' in fruits
Dlen('apple') in fruits
What will len([]) output?
A1
B0
CNone
DError
What does 7 not in [1, 2, 3, 4] return?
ATrue
BFalse
C7
DError
If my_list = ['a', 'b', 'c'], what is 'd' in my_list?
AError
BTrue
C'd'
DFalse
Explain how to find the length of a list and check if an item is inside it in Python.
Think about how you count items and how you ask if something is present.
You got /3 concepts.
    Describe what happens when you use not in with a list.
    It's like asking if something is missing.
    You got /3 concepts.