Question Detail

COS 102 lecture 4 Objective Question

Question

What happens when you use the '+' operator with a string and a number in a Python `print()` statement?
Options
A Python automatically converts the number to a string and concatenates them.
B Python performs arithmetic if the string contains a valid number.
C Python will give an error.
Correct Answer
D Python stores both values in a tuple and prints it.
Correct Answer

Option C is the correct answer.

Detailed Explanation

Page 34 demonstrates this: 'If you try to combine a string and a number, Python will give you an error:' with an example showing print (x + y) where x=5 (int) and y='John' (str) would cause an error.

Hint

Review the 'Output Variables' section, specifically the second example on page 34.

Question Info