Question Detail

COS 102 Python strings Objective Question

Question

To correctly concatenate the string "Age: " with the number 20 without causing a TypeError, which Python function should be used to convert the number?
Options
A <code>int()</code>
B <code>float()</code>
C <code>str()</code>
Correct Answer
D <code>list()</code>
Correct Answer

Option C is the correct answer.

Detailed Explanation

The 'Avoid the TypeError' section (page 10) provides 'The Fix: Convert the number to a string first using str(). "Age: " + str(20) → "Age: 20"'.

Hint

The solution involves converting the number into a string before concatenation.

Question Info