Question Detail

COS 102 6 lecture note; fundamentals of programming Objective Question

Question

Analyze the following Python code snippet:
sum = lambda a,b : a+b
print (sum(5,6))
print sum(10,30)
Assuming this code is run in a Python 3.x environment, what will be the outcome?
Options
A 11<br>40
B 11, 40
C Error
Correct Answer
D None of the above
Correct Answer

Option C is the correct answer.

Detailed Explanation

The first print statement print (sum(5,6)) uses Python 3 function syntax for print, and sum(5,6) correctly evaluates to 11. The second print statement print sum(10,30) uses Python 2 statement syntax for print. In Python 3, print is a function and requires parentheses for its arguments. Therefore, print sum(10,30) would result in a SyntaxError in Python 3.x.

Hint

Distinguish between Python 2 and Python 3 syntax, specifically regarding the `print` function/statement.

Question Info