WorksheetsPython: Making a List
Total questions: 10
Worksheet time: 5mins
Which of the following is the correct way to create an empty list in Python?
list = {}
list = ()
list = []
list = empty
Which of the following creates a list containing three fruits?
fruits = ["apple", "banana", "cherry"]
fruits = "apple", "banana", "cherry"
fruits = {"apple", "banana", "cherry"}
fruits = "apple" + "banana" + "cherry"
What is the output of the following code? numbers = [] numbers.append(5) print(numbers)
5
[5]
(5)
{5}
Which method is used to add a single element to the end of a list?
add()
insert()
append()
extend()
What will be the content of colours after running the code below?
red
green
What is the correct way to take a user’s input and add it to a list called names?
input(names.append())
name = input("Enter name: ") names.append(name)
names.input().append("Enter name: ")
append(input("Enter name: "))
What will this code print?
It prints only the last item entered.
It prints both items entered as a list.
It prints the word “items”.
It shows an error.
What does the following line of code do? my_list = list()
Creates a list with one element called “list”.
Creates an empty list.
Deletes all lists.
Which statement will add “orange” to this list correctly? fruits = ["apple", "banana"]
append("orange", fruits)
fruits.add("orange")
fruits.append("orange")
fruits.insert("orange")
What will be the output of this code? my_list = [] user_input = "Python" my_list.append(user_input) print(my_list)
A. Python
B. ['user_input']
C. [Python]
D. ['Python']
