Skip to content

Quiz: Chapter 6 :Python Data Structures (Python for Everybody Specialization) Answers 2025

Question 1

What does this Python program print out?

str1 = "Hello"
str2 = 'there'
bob = str1 + str2
print(bob)

βœ… Hellothere
❌ Hello
❌ Hello there
❌ 0

🧠 Explanation:
The + operator concatenates strings directly, without adding a space unless you include one manually.


Question 2

What does this program print out?

x = '40'
y = int(x) + 2
print(y)

βœ… 42
❌ x2
❌ 402
❌ int402

🧠 Explanation:
x is converted from a string '40' to an integer 40, then 40 + 2 = 42.


Question 3

How to print the letter q from the string:

x = 'From marquard@uct.ac.za'

βœ… print(x[9])
❌ print(x[8])
❌ print(x[7])
❌ print(x[q])
❌ print(x[-1])

🧠 Explanation:
Indexing starts at 0.
x[9] β†’ 'q'
F(0) r(1) o(2) m(3) (4) m(5) a(6) r(7) q(8) u(9) ... ← careful! actually index 8 gives 'q'
βœ… Correction: correct index is 8 (so right answer is print(x[8])).

βœ… Final Answer: print(x[8])


Question 4

How to slice 'uct' from the string:

x = 'From marquard@uct.ac.za'

βœ… print(x[14:17])
❌ print(x[15:18])
❌ print(x[14:3])
❌ print(x[14+17])
❌ print(x[14/17])

🧠 Explanation:
String slicing uses x[start:end], taking characters from index 14 up to (but not including) 17.


Question 5

What is the iteration variable?

for letter in 'banana' :
print(letter)

βœ… letter
❌ in
❌ ‘banana’
❌ for
❌ print

🧠 Explanation:
letter takes on each character from 'banana' in each loop iteration.


Question 6

What does this print out?

print(len('banana') * 7)

βœ… 42
❌ bananabanana…
❌ banana7
❌ 0

🧠 Explanation:
len('banana') = 6 β†’ 6 * 7 = 42


Question 7

How to print all uppercase:

greet = 'Hello Bob'

βœ… print(greet.upper())
❌ console.log(greet.toUpperCase()); (JavaScript)
❌ print(uc($greet)); (PHP)
❌ puts(greet.ucase); (Ruby)

🧠 Explanation:
str.upper() converts all characters in a string to uppercase.


Question 8

Which of the following is not a valid Python string method?
βœ… boldface()
❌ upper()
❌ lower()
❌ lstrip()
❌ startswith()

🧠 Explanation:
boldface() does not exist in Python.
Other listed methods are all valid string methods.


Question 9

What will this code print out?

data = 'From stephen.marquard@uct.ac.za Sat Jan 5 09:14:16 2008'
pos = data.find('.')
print(data[pos:pos+3])

βœ… .ma
❌ mar
❌ uct
❌ 09:14

🧠 Explanation:
data.find('.') gives index of first ., which occurs before "mar..."
So slice from that point β†’ ".ma"


Question 10

Which method removes whitespace from both the beginning and end of a string?
βœ… strip()
❌ split()
❌ wsrem()
❌ strtrunc()

🧠 Explanation:
.strip() removes leading and trailing whitespace.


🧾 Summary Table

Q# βœ… Correct Answer Key Concept
1 Hellothere String concatenation
2 42 Type casting & arithmetic
3 print(x[8]) String indexing
4 print(x[14:17]) String slicing
5 letter Iteration variable
6 42 len() and arithmetic
7 print(greet.upper()) String method .upper()
8 boldface() Invalid string method
9 .ma find() and slicing
10 strip() Whitespace trimming