NEW
Font size
WorksheetsList Items: Definition and Indexing
Total questions: 40
Worksheet time: 20mins
Which statement correctly defines a Python list?
A single number stored in a variable
A collection used to store multiple items in one variable, written with square brackets [ ]
A function that prints text
A type of loop that repeats code
Given fruits = ["apple", "banana", "cherry"], what does print(fruits[0]) output?
banana
apple
cherry
['apple', 'banana', 'cherry']
With fruits = ["apple", "banana", "cherry"], which item is accessed by print(fruits[-1])?
apple
banana
cherry
It causes an error
Which Python list correctly represents five fruits as strings?
[apple, banana, mango, grape, orange]
['apple', 'banana', 'mango', 'grape', 'orange']
['apple' 'banana' 'mango' 'grape' 'orange']
('apple', 'banana', 'mango', 'grape', 'orange')
You are asked to create a list of your favorite colors. Which option shows a valid Python list of color names?
['blue', 'green', 'purple']
{ 'blue', 'green', 'purple' }
('blue', 'green', 'purple')
["blue"; "green"; "purple"]
A mixed list can contain numbers, strings, and booleans. Which option best demonstrates such a mixed list?
[True, False, None]
[1, 2, 3, 4]
['red', 'blue', 'green']
[42, 'hello', True]
In Python, which function is used to check the data type of a variable like a list?
len()
type()
list()
print()
In Python, lists are described as mutable. What does this mean?
You cannot change the items once the list is created
You can change the items in the list after it is created
Lists automatically sort themselves
Lists can only store numbers
Given animals = ["cat", "dog", "rabbit"], which line of code changes "dog" to "lion"?
animals[0] = "lion"
animals[1] = "lion"
animals[2] = "lion"
animals[3] = "lion"
After running the code animals = ["cat", "dog", "rabbit"]; animals[1] = "lion"; print(animals), what is printed?
['cat', 'dog', 'rabbit']
['lion', 'dog', 'rabbit']
['cat', 'lion', 'rabbit']
['cat', 'dog', 'lion']
Which list index would you use to change the 2nd color in a list in Python?
0
1
2
-1
You have fruits = ['apple','banana','cherry']. Which single operation correctly replaces the last fruit with 'mango'?
fruits[0] = 'mango'
fruits[1] = 'mango'
fruits[2] = 'mango'
fruits.append('mango')
Given numbers = [10, 20, 30, 40], what is the correct way to change the first number to 99?
numbers[1] = 99
numbers[0] = 99
numbers[-1] = 99
numbers.insert(0, 99)
Which Python list method adds a single item to the end of the list?
insert()
append()
extend()
add()
You have a list: fruits = ["apple", "banana"]. Which code will place "orange" between "apple" and "banana"?
fruits.append("orange")
fruits.insert(1, "orange")
fruits.extend(["orange"])
fruits.insert(0, "orange")
What is the primary purpose of the extend() method?
To add one item at the end
To remove an item
To insert an item at a position
To add all items from another list
Which Python list method adds a single new item to the end of an existing list?
insert()
append()
extend()
pop()
You have colors = ["red", "blue"]. Which code inserts "green" at the start so the list becomes ["green", "red", "blue"]?
colors.append("green")
colors.extend(["green"])
colors.insert(0, "green")
colors.pop(0, "green")
Given cities = ["Paris"]. Which snippet appends two new cities individually, ending with ["Paris", "Lagos", "Seoul"]?
cities.extend(["Lagos", "Seoul"])
cities.append(["Lagos", "Seoul"])
cities.append("Lagos"); cities.append("Seoul")
cities.insert(2, ["Lagos", "Seoul"])
If fruits = ["apple"] and more = ["banana", "mango"], which expression correctly extends fruits with another list so the result is ["apple", "banana", "mango"]?
fruits.append(more)
fruits.insert(1, more)
fruits.extend(more)
fruits.pop(more)
You have a list nums = [10, 20, 30, 40]. Which option correctly removes the item at index 2?
nums.remove(2)
del nums(2)
nums.pop(2)
nums.clear(2)
Which statement would empty a list named items without deleting the variable itself?
items.clear()
del items
items.pop()
items.remove('all')
You have list nums = [4, 7, 9]. Which option correctly removes the last item using a simple procedure?
nums.remove(9)
nums.pop()
del nums[0]
nums.clear()
Given colors = ["red", "green", "blue"], which statement deletes the first element by index?
del colors[0]
colors.pop(2)
colors.remove("blue")
colors.clear()
Which operation will empty a list so that it still exists but contains no items?
del my_list
my_list.clear()
my_list.pop()
my_list.remove(my_list[0])
In Python, which code snippet correctly iterates through each item in a list named fruits and prints it?
for fruits in fruit:\n print(fruits)
for fruit in fruits:\n print(fruit)
print(fruits for fruit)
loop fruits:\n print(fruit)
Given the list fruits = ["apple", "banana", "cherry"], what will be printed by the following code?\n\nfor fruit in fruits:\n print(fruit)
apple banana cherry (each on its own line)
apple, banana, cherry on one line
fruit fruit fruit
Nothing; the code has a syntax error
Which loop statement is most appropriate to print all items in a list one by one?
for item in list: print(item)
if item in list: print(item)
while item == list: print(item)
print(list) and stop
You have a list of numbers. Which code prints each number doubled (x2)?
for n in numbers: print(n*2)
for n in numbers: print(n+2)
for n in numbers: print(n/2)
for n in numbers: print(2/n)
Which condition inside a loop will print items that start with 'A'? Assume item is a string.
if item.startswith('A'): print(item)
if 'A' in item[0]: print(item)
if item == 'A*': print(item)
if item.endswith('A'): print(item)
Given fruits = ["apple", "banana", "cherry", "mango", "orange"], what is returned by print(fruits[-2])?
apple
banana
mango
orange
Given numbers = [10, 20, 30, 40, 50, 60], what does print(numbers[-3:]) output?
[10, 20, 30]
[30, 40, 50]
[40, 50, 60]
[50, 60]
For numbers = [10, 20, 30, 40, 50, 60], which slice returns [10, 20, 30, 40]?
numbers[0:4]
numbers[-3:]
numbers[:-2]
numbers[-1]
A student wants the second last fruit from fruits = ["apple", "banana", "cherry", "mango", "orange"]. Which index should they use and why?
Use index 3 because counting starts at 0.
Use index -1 because it accesses the second last item.
Use index -2 because negative indexing counts from the end.
Use index 1 because it is the second item.
In Python, which negative index accesses the last element of a list?
-2
-1
0
1
Given fruits = ['apple','banana','cherry','date'], which statement prints the last and second last fruit?
print(fruits[-1], fruits[-2])
print(fruits[3], fruits[2])
print(fruits[0], fruits[1])
print(fruits[-2], fruits[-3])
cities = ['Lagos','Delhi','Tokyo','Paris','Nairobi','Rome']. Which expression prints the 3rd city from the end?
cities[-3]
cities[3]
cities[-2]
cities[2]
colors = ['red','green','blue','yellow','purple','orange']. Which slice prints the last 3 colors?
colors[-3:]
colors[3:]
colors[:-3]
colors[-1:-3]
movies = ['Dune','Mulan','Coco','Moana','Avatar']. Which option prints the first and last movie using negative indexing combined with standard indexing?
print(movies[0], movies[-1])
print(movies[-0], movies[-1])
print(movies[1], movies[-1])
print(movies[-5], movies[-1])
You have a list numbers = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30]. Which slice prints the last five elements using negative indexing?
numbers[-5:]
numbers[5:]
numbers[:-5]
numbers[-1:-6]
