Examveda

What will be the output of the following Python function?
sum(2,4,6)
sum([1,2,3])

A. Error, 6

B. 12, Error

C. 12, 6

D. Error, Error

Answer: Option A

Solution (By Examveda Team)

For the call sum(2, 4, 6), the sum() function in Python expects an iterable (like a list, tuple, etc.) as its argument. When you pass individual values separated by commas, it will raise a TypeError because it doesn't accept multiple arguments like that.

For the call sum([1, 2, 3]), it calculates the sum of the elements in the list [1, 2, 3], which would be 6.

Therefore, the first call will result in an error, and the second call will result in the sum of the elements of the list, which is 6. So, the correct output is Error, 6.

This Question Belongs to Python Program >> Python Built In Functions

Join The Discussion

Related Questions on Python Built In Functions