Python Lists Basics Quiz

Python
0 Passed
0% acceptance

A 35-question quiz covering list creation, indexing, appending, inserting, removing, updating, and length checking.

35 Questions
~70 minutes
1

Question 1

Which syntax is used to create a list in Python?

A
Square brackets []
B
Parentheses ()
C
Curly braces {}
D
Angle brackets <>
2

Question 2

How do you access the first element of a list named 'my_list'?

A
my_list[0]
B
my_list[1]
C
my_list.first()
D
my_list.get(0)
3

Question 3

Which method adds an element to the end of a list?

A
append()
B
add()
C
push()
D
insert()
4

Question 4

What does the remove() method do?

A
Removes the first occurrence of a specified value
B
Removes an element at a specific index
C
Removes the last element
D
Deletes the entire list
5

Question 5

How do you change the value of the second item in a list?

A
my_list[1] = new_value
B
my_list[2] = new_value
C
my_list.update(1, new_value)
D
my_list.set(1, new_value)
6

Question 6

Which function returns the number of items in a list?

A
len()
B
count()
C
size()
D
length()
7

Question 7

What happens if you try to access an index that does not exist?

A
IndexError
B
ValueError
C
KeyError
D
None is returned
8

Question 8

What is the result of this code?

python
fruits = ["apple", "banana", "cherry"]
print(fruits[-1])
A
cherry
B
banana
C
apple
D
Error
9

Question 9

Which method allows you to add an element at a specific position?

A
insert()
B
append()
C
add()
D
extend()
10

Question 10

What does pop() do if no index is specified?

A
Removes and returns the last item
B
Removes and returns the first item
C
Clears the list
D
Raises an error
11

Question 11

What is the output of this code?

python
numbers = [10, 20, 30]
numbers[0] = 15
print(numbers)
A
[15, 20, 30]
B
[10, 15, 30]
C
[10, 20, 15]
D
Error
12

Question 12

How do you create an empty list?

A
my_list = []
B
my_list = {}
C
my_list = ()
D
my_list = list(0)
13

Question 13

What is the output?

python
colors = ["red", "green"]
colors.append("blue")
print(len(colors))
A
3
B
2
C
4
D
Error
14

Question 14

Which statement correctly removes 'banana' from the list?

python
fruits = ["apple", "banana", "cherry"]
A
fruits.remove('banana')
B
fruits.delete('banana')
C
fruits.pop('banana')
D
del fruits['banana']
15

Question 15

What happens when you use insert() at an index larger than the list length?

A
The item is added to the end
B
IndexError
C
The list remains unchanged
D
It fills the gap with None
16

Question 16

What is the result of this code?

python
nums = [1, 2, 3]
nums.pop(1)
print(nums)
A
[1, 3]
B
[1, 2]
C
[2, 3]
D
[1, 2, 3]
17

Question 17

Can a list contain items of different data types?

A
Yes, lists can be mixed
B
No, they must be all same type
C
Only numbers and strings
D
Only if declared as mixed
18

Question 18

What is the output?

python
a = [10, 20]
b = a
b[0] = 99
print(a[0])
A
99
B
10
C
20
D
Error
19

Question 19

Which of these is a valid way to delete the item at index 0?

A
del my_list[0]
B
delete my_list[0]
C
remove my_list[0]
D
erase my_list[0]
20

Question 20

What does this code print?

python
items = ["a", "b", "c", "d"]
print(items[1:3])
A
['b', 'c']
B
['a', 'b', 'c']
C
['b', 'c', 'd']
D
['c', 'd']
21

Question 21

How do you check if 'apple' is in the list 'fruits'?

A
'apple' in fruits
B
fruits.contains('apple')
C
fruits.has('apple')
D
check('apple', fruits)
22

Question 22

What is the result of multiplying a list by an integer?

python
print([1, 2] * 2)
A
[1, 2, 1, 2]
B
[2, 4]
C
[1, 2, 2]
D
Error
23

Question 23

What is the output?

python
lst = [1, 2, 3]
lst.insert(1, 5)
print(lst)
A
[1, 5, 2, 3]
B
[1, 2, 5, 3]
C
[5, 1, 2, 3]
D
[1, 2, 3, 5]
24

Question 24

Which method clears all items from a list?

A
clear()
B
empty()
C
delete()
D
remove_all()
25

Question 25

What happens if you try to remove an item that is not in the list?

A
ValueError
B
IndexError
C
Nothing happens
D
False is returned
26

Question 26

What is the output?

python
x = [1, 2, 3]
y = x + [4]
print(y)
A
[1, 2, 3, 4]
B
[1, 2, 3, [4]]
C
Error
D
[[1, 2, 3], 4]
27

Question 27

How do you find the index of the first occurrence of 'x'?

A
list.index('x')
B
list.find('x')
C
list.search('x')
D
list.locate('x')
28

Question 28

What is the output?

python
nums = [5, 10, 15]
nums[1] = 20
print(nums[-2])
A
20
B
10
C
15
D
5
29

Question 29

Which of the following creates a list with numbers 0 to 4?

A
list(range(5))
B
[0..4]
C
range(5).to_list()
D
list(0, 5)
30

Question 30

What is the output?

python
a = [1, 2]
a.extend([3, 4])
print(len(a))
A
4
B
3
C
2
D
1
31

Question 31

What is the result of this code?

python
lst = ["a", "b", "c"]
del lst[1]
print(lst)
A
['a', 'c']
B
['a', 'b']
C
['b', 'c']
D
['a', None, 'c']
32

Question 32

What is the output?

python
data = [1]
data.append(data)
print(len(data))
A
2
B
1
C
Infinite
D
Error
33

Question 33

Which method reverses the order of the list in place?

A
reverse()
B
reversed()
C
invert()
D
backwards()
34

Question 34

What is the output?

python
vals = [10, 20, 30]
vals.insert(0, 5)
print(vals[1])
A
10
B
5
C
20
D
30
35

Question 35

What does this code output?

python
a = [1, 2, 3]
b = a[:]
b[0] = 9
print(a[0])
A
1
B
9
C
2
D
Error

QUIZZES IN Python