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:
Explanation:
-
-
-
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?✗ Incorrect
The list has 3 items, so
len() returns 3.Which expression checks if 'apple' is in the list
fruits?✗ Incorrect
The correct syntax to check membership is
item in list.What will
len([]) output?✗ Incorrect
An empty list has zero items, so
len([]) returns 0.What does
7 not in [1, 2, 3, 4] return?✗ Incorrect
Since 7 is not in the list, the expression returns True.
If
my_list = ['a', 'b', 'c'], what is 'd' in my_list?✗ Incorrect
'd' is not in the list, so the expression returns False.
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.