Test your understanding with 12 questions. You need 70% (9 out of 12) to pass. Good luck!
What is the correct way to create an empty list in Python?
list = ()
my_list = []
my_list = {}
my_list = empty()
[]
Given fruits = ["apple", "banana", "cherry", "date"], what does fruits[2] return?
fruits = ["apple", "banana", "cherry", "date"]
fruits[2]
"banana"
"apple"
"cherry"
"date"
Given nums = [10, 20, 30, 40, 50], what does nums[-2] return?
nums = [10, 20, 30, 40, 50]
nums[-2]
20
50
30
40
What is the difference between append() and extend()?
append()
extend()
What does pop() do when called without arguments?
pop()
Given data = [5, 3, 8, 1, 9], what does data.sort() return?
data = [5, 3, 8, 1, 9]
data.sort()
None
[1, 3, 5, 8, 9]
[9, 8, 5, 3, 1]
sort()
sorted()
Given nums = [1, 2, 3, 4, 5, 6, 7, 8], what does nums[2:6] return?
nums = [1, 2, 3, 4, 5, 6, 7, 8]
nums[2:6]
[2, 3, 4, 5, 6]
[3, 4, 5, 6]
[3, 4, 5]
[2, 3, 4, 5]
What does my_list[::-1] do?
my_list[::-1]
[::-1]
What happens when you write copy = original with lists?
copy = original
[:]
.copy()
What does this list comprehension produce? [x * 2 for x in range(5)]
[x * 2 for x in range(5)]
[0, 2, 4, 6, 8]
[2, 4, 6, 8, 10]
[1, 2, 3, 4, 5]
[0, 1, 2, 3, 4]
What does [x for x in range(10) if x % 2 == 0] produce?
[x for x in range(10) if x % 2 == 0]
[1, 3, 5, 7, 9]
x % 2 == 0
Which of the following is the best use case for a list comprehension?