Knowee
Questions
Features
Study Tools

What will be the output of the following Python code?def foo(fname, val): print(fname(val))foo(max, [1, 2, 3])foo(min, [1, 2, 3])

Question

What will be the output of the following Python code?

def foo(fname, val):
    print(fname(val))

foo(max, [1, 2, 3])
foo(min, [1, 2, 3])
🧐 Not the exact question you are looking for?Go ask a question

Solution

The output of the Python code will be:

3 1

Explanation:

The function foo takes two arguments: a function fname and a list val.

In the first call to foo, max is passed as fname and [1, 2, 3] as val. The max function returns the maximum value in the list, which is 3. This value is then printed.

In the second call to foo, min is passed as fname and [1, 2, 3] as val. The min function returns the minimum value in the list, which is 1. This value is then printed.

This problem has been solved

Similar Questions

What is the output of the following function calldef fun1(name, age=20):    print(name, age) fun1('Emma', 25)Emma 25Emma 20Emma 22

What will be the output of the following Python code?def foo(k): k = [1]q = [0]foo(q)print(q) [0][1][1, 0][0, 1]

What will be the output of the following code?arr=[1,4,8,10,18,6,9]print(max(arr), len(arr), min(arr), arr.remove(4), arr.pop())

What will be the output of the following Python code?1.  def foo():2.     try:3.       print(1)4.    finally:5.        print(2)6.   7.  foo()

What will be the output of the following Python code?L = [lambda x: x ** 2, lambda x: x ** 3, lambda x: x ** 4] for f in L: print(f(3))

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.