How do you create an empty list in python?
A. my_list = []
B. my_list = ()
What does negative indexing mean in lists?
Counting from the end (e.g. -1 is last element)
What method adds an item to the end of a list?
.append()
What keyword starts a for loop in Python?
for
What operator checks if an item exists in a list?
in
What is the index of the first element in a Python list?
0
Given letters = ['a', 'b', 'c', 'd'], what is letters[-1]?
'd'
What method removes the first matching element from a list?
.remove()
What does this loop print? for x in [1, 2, 3]: print(x)
1, 2, 3
What is the output of
'a' in ['a', 'b', 'c']?
True
Given nums = [10, 20, 30, 40], what does nums[2] return?
30
Given nums = [2, 4, 6, 8, 10], what does nums[1:4] return?
[4, 6, 8]
Given nums = [1, 2, 3], what is the result after nums.append(4)?
[1, 2, 3, 4]
How many times does this loop run? for x in [10, 20, 30, 40]: print(x)
4 times
What function returns the number of elements in a list?
len()
What happens if you try to access an index that doesn’t exist?
You get an error.
Given fruits = ['apple', 'banana', 'cherry', 'date'], what does fruits[:-1] return?
['apple', 'banana', 'cherry']
Given fruits = ['apple', 'banana', 'cherry'] and fruits.remove('banana'), what is the new list?
['apple', 'cherry']
What is the output?
nums = [1, 2, 3]
total = 0
for n in nums:
total += n
print(total)
6
Given nums = [3, 6, 9, 12], what is len(nums)?
4
What type of data structure is a list in Python — mutable or immutable?
Mutable
Given nums = [1, 2, 3, 4, 5], what does nums[::-1] do?
Reverses the list → [5, 4, 3, 2, 1]
How do you combine two lists, a = [1, 2] and b = [3, 4], into one list?
a + b
What does this code print?
for i in range(len(['a','b','c'])):
print(i)
0, 1, 2
What is the output of
'cat' not in ['dog', 'bird', 'fish']?
True