Question Detail
Question
Consider the Python code snippet from slide 12:
sum = lambda a,b : a+b
print (sum(5,6))
print sum(10,30)
What is the expected output?
Correct Answer
Option C is the correct answer.
Detailed Explanation
The first
print (sum(5,6)) will correctly print 11. However, the second print sum(10,30) uses Python 2 syntax for the print statement without parentheses. In Python 3 (which is implied by 'Python Quiz' and the general context of modern Python education), this will cause a SyntaxError.
Hint
Consider the Python version being used. How does the
print function work in modern Python (Python 3)?