Question Detail

COS 102 lecture 4 Objective Question

Question

What happens if you try to combine a string and a number using the '+' character in a Python print statement?
Options
A Python automatically converts the number to a string and concatenates them.
B Python treats the string as a number and attempts arithmetic addition.
C Python will give you an error.
Correct Answer
D Python prints the string followed by the number, separated by a space.
Correct Answer

Option C is the correct answer.

Detailed Explanation

Page 34 explicitly states, 'If you try to combine a string and a number, Python will give you an error.' It provides an example illustrating this.

Hint

Recall the examples shown for the '+' operator with different data types on page 34.

Question Info