Python Sequence Collections Quiz

Python
0 Passed
0% acceptance

A 30-question quiz focused on Python lists, covering list creation, indexing, slicing, mutation, iteration, list methods, copying behavior, and practical data-handling scenarios.

30 Questions
~60 minutes
1

Question 1

Why are lists considered one of Python's most versatile data structures?

A
They can store mixed data types, support indexing and slicing, and allow modifications in place
B
They can only store numbers but sort them automatically
C
They store data permanently on disk
D
They convert themselves into dictionaries when needed
2

Question 2

What is one advantage of list mutability in Python?

A
Elements can be added, removed, or changed without recreating the entire list
B
Lists can automatically resize files
C
Mutability prevents index errors
D
Mutability forces lists to store identical types
3

Question 3

A developer needs to maintain the order of elements while storing values that can change over time. Why is a list a suitable choice?

A
Because lists preserve insertion order and allow modifications
B
Because lists randomize values on insert
C
Because lists automatically enforce sorting
D
Because lists cannot store duplicates
4

Question 4

Which indexing rule applies to Python lists?

A
Indexing starts at 0 for the first element
B
Indexing starts at 1 for the first element
C
Negative indexes are not allowed
D
Indexes must always be strings
5

Question 5

Which list method removes and returns the last element by default?

A
pop()
B
remove()
C
clear()
D
discard()
6

Question 6

Why is append() often preferred when adding items one at a time?

A
append() adds a single element efficiently at the end of the list
B
append() inserts items at random positions
C
append() forces the list to become sorted
D
append() automatically filters out duplicates
7

Question 7

What happens when you attempt to access an index outside the boundaries of a list?

A
Python raises an IndexError
B
Python returns None
C
Python automatically resizes the list
D
Python replaces missing items with zeros
8

Question 8

A developer wants to remove the first occurrence of a specific value in a list. Which method should they use?

A
remove()
B
pop()
C
discard()
D
cut()
9

Question 9

Why might slicing be used when working with lists?

A
To create a portion of the list without affecting the original
B
To replace the list with a dictionary
C
To automatically reverse nested lists
D
To validate the content of the list
10

Question 10

A list stores items representing inventory counts. The system must update values frequently as stock changes. Why is using a list appropriate in this scenario?

A
Because lists offer efficient element updates through indexing
B
Because lists automatically sync with databases
C
Because lists are immutable and prevent accidental changes
D
Because lists sort themselves on every update
11

Question 11

A program receives a long list of temperature readings, and the developer needs to keep only the first 24 values, representing hourly readings for one day. Why is slicing (readings[:24]) a simple and safe solution for this extraction?

A
It cleanly returns the desired range without modifying the original list
B
It automatically deletes all other values
C
It raises errors if the list has fewer than 24 values
D
It converts all non-numeric values into zeros
12

Question 12

A user interface displays product categories stored in a list. New categories must be added at the end of the list as they appear. Why is append() suited for this task?

A
It adds a new element at the end efficiently and preserves order
B
It forces items into alphabetical order
C
It prevents duplicate categories from being added
D
It inserts items at the beginning
13

Question 13

A developer duplicates a list with copy_list = original_list but discovers that modifying copy_list also changes original_list. Why is this happening?

A
Because this assignment creates a reference to the same underlying list
B
Because Python merges both lists automatically
C
Because lists become immutable when copied
D
Because Python stores all lists globally
14

Question 14

A collection of grades must be sorted before generating a report. Why is the sort() method appropriate rather than creating a separate loop to reorder values manually?

A
sort() provides efficient built-in sorting optimized for Python lists
B
sort() validates numeric ranges automatically
C
sort() prevents None values from appearing
D
sort() guarantees alphabetical ordering for any list
15

Question 15

A developer needs to flatten a list of lists into a single list. Why is using a nested loop or a comprehension like [item for sub in L for item in sub] a common technique?

A
Because each nested list must be iterated individually, and comprehensions provide readable flattening
B
Because lists flatten themselves when assigned
C
Because flattening deletes all None values automatically
D
Because flattening forces the list to become a set
16

Question 16

What does this code print?

python
nums = [10, 20, 30]
      print(nums[1])
A
20
B
10
C
30
D
Error
17

Question 17

What is printed when slicing this list?

python
vals = [1, 2, 3, 4, 5]
      print(vals[1:4])
A
[2, 3, 4]
B
[1, 2, 3]
C
[2, 3, 4, 5]
D
[3, 4]
18

Question 18

What does append() do in this code?

python
items = ["a"]
      items.append("b")
      print(items)
A
['a', 'b']
B
['b', 'a']
C
['a']
D
Error
19

Question 19

What is printed here?

python
stuff = [1, 2, 3]
      stuff.pop()
      print(stuff)
A
[1, 2]
B
[1, 3]
C
[2, 3]
D
Error
20

Question 20

What does this code print?

python
data = [3, 1, 2]
      data.sort()
      print(data)
A
[1, 2, 3]
B
[3, 2, 1]
C
[3, 1, 2]
D
Error
21

Question 21

What will be the output of this reverse slice?

python
print([1, 2, 3, 4][::-1])
A
[4, 3, 2, 1]
B
[1, 2, 3, 4]
C
[3, 4]
D
Error
22

Question 22

What is printed by this nested list access?

python
grid = [[0, 1], [2, 3]]
      print(grid[1][0])
A
2
B
1
C
0
D
Error
23

Question 23

What is printed here?

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

Question 24

What does extend() do here?

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

Question 25

What happens when you use clear()?

python
nums = [1, 2, 3]
      nums.clear()
      print(nums)
A
[]
B
[1, 2, 3]
C
None
D
Error
26

Question 26

Why is list comprehension often preferred over manual loops for creating filtered lists?

A
It provides concise syntax while keeping logic readable
B
It prevents index errors automatically
C
It forces all values to become strings
D
It supports recursion inherently
27

Question 27

Why should shallow copying be used cautiously when working with nested lists?

A
Because inner lists remain shared, causing changes to propagate unexpectedly
B
Because shallow copies delete nested lists
C
Because shallow copying does not allow iteration
D
Because nested lists become immutable
28

Question 28

A list stores values representing monthly sales. The business needs to compute the total. Why is using sum() considered a clean and idiomatic approach?

A
sum() handles numeric iterables efficiently and makes code easier to read
B
sum() also calculates averages automatically
C
sum() converts strings to numbers
D
sum() validates the list length
29

Question 29

Why are negative indexes useful when working with lists?

A
They provide a convenient way to access elements relative to the end of the list
B
They automatically reverse the list
C
They create shallow copies
D
They prevent index errors
30

Question 30

What is a common benefit of using enumerate() when iterating over lists?

A
It pairs each element with its index, improving readability and eliminating manual index tracking
B
It forces a list to sort itself
C
It removes duplicate items
D
It converts the list into a dictionary

QUIZZES IN Python