Quiz: Chapter 6 :Python Data Structures (Python for Everybody Specialization) Answers 2025
Question 1
What does this Python program print out?
β
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?
β
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:
β
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:
β
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?
β
letter
β in
β ‘banana’
β for
β print
π§ Explanation:letter takes on each character from 'banana' in each loop iteration.
Question 6
What does this print out?
β
42
β bananabananaβ¦
β banana7
β 0
π§ Explanation:len('banana') = 6 β 6 * 7 = 42
Question 7
How to print all uppercase:
β
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?
β
.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 |