Skip to content

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’?

friends = ['Joseph', 'Glenn', '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?

fruit = 'Banana'
fruit[0] = 'b'
print(fruit)

βœ… 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:

x = list(range(5))

βœ… 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?

a = [1, 2, 3]
b = [4, 5, 6]
c = a + b
print(len(c))

βœ… 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 = [9, 41, 12, 3, 74, 15]

βœ… 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?

friends = ['Joseph', 'Glenn', 'Sally']
friends.sort()
print(friends[0])

βœ… 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