Quiz: Chapter 8 :Python Data Structures (Python for Everybody Specialization) Answers 2025
Question 1
How are “collection” variables different from normal variables?
β
Collection variables can store multiple values in a single variable
β Can only store a single value
β Pull multiple network documents together
β Merge output streams
π§ Explanation:
A collection variable (like a list, tuple, or dictionary) holds multiple values under one variable name.
Question 2
What Python keywords are used to loop through a list?
β
for / in
β try / except
β foreach / in
β def / return
π§ Explanation:
The for ... in syntax is used for iterating over items in a collection (e.g. for item in my_list:).
Question 3
How to print ‘Sally’?
β
print(friends[2])
β print(friends[3])
β print(friends[‘Sally’])
β print(friends[2:1])
π§ Explanation:
List indexing starts from 0 β Sally is at index 2.
Question 4
What does this code do?
β
Nothing would print β the program fails with a traceback error
β banana
β b
β Banana
π§ Explanation:
Strings are immutable β you canβt modify them by index.
Question 5
Which statement prints the length of a list named data?
β
print(len(data))
β print(data.length)
β print(data.length())
β print(strlen(data))
β print(length(data))
π§ Explanation:len() is the built-in function that returns the length of sequences like lists, strings, tuples, etc.
Question 6
What type of data is produced when you call:
β
A list of integers
β A string
β A list of words
β A list of characters
β A boolean
π§ Explanation:range(5) β [0,1,2,3,4] after converting to list.
Question 7
What does this code print?
β
6
β 15
β [1, 2, 3, 4, 5, 6]
β 21
π§ Explanation:a + b joins both lists into [1,2,3,4,5,6].len(c) = 6 elements.
Question 8
Which slicing operation produces [12, 3]?
β
t[2:4]
β t[1:3]
β t[:]
β t[2:2]
β t[12:3]
π§ Explanation:t[2:4] picks elements at indexes 2 and 3 β [12, 3].
Question 9
What list method adds a new item to the end of a list?
β
append()
β push()
β add()
β pop()
β index()
π§ Explanation:list.append(item) adds an element to the end of a list in Python.
Question 10
What will this print?
β
Glenn
β Joseph
β Sally
β friends
π§ Explanation:.sort() arranges the list alphabetically β ['Glenn', 'Joseph', 'Sally'].
Index [0] = βGlennβ.
π§Ύ Summary Table
| Q# | β Correct Answer | Key Concept |
|---|---|---|
| 1 | Can store multiple values | Collection vs normal variable |
| 2 | for / in | Looping through lists |
| 3 | print(friends[2]) | List indexing |
| 4 | Program fails (immutable string) | String immutability |
| 5 | print(len(data)) | Length function |
| 6 | List of integers | range() + list() |
| 7 | 6 | List concatenation + len() |
| 8 | t[2:4] | List slicing |
| 9 | append() | Add element to list |
| 10 | Glenn | Sorting lists alphabetically |