निम्नलिखित पायथन कोड का आउटपुट क्या होगा?
What will be the output of the following Python code ?
import functools
l=[1, 2, 3, 4, 5]
m=functools.reduce(lambda x, y:x if x>y else y, l)
print(m)
A)
B)
C)
D)
Explanation:
The code uses functools.reduce()
to find the largest number in the list l = [1, 2, 3, 4, 5]
.
- The
lambda x, y: x if x > y else y
function compares two numbers at a time and keeps the larger one. - After comparing all elements, the largest number
5
is stored inm
.
Output:
(D) 5