निम्नलिखित पायथन कोड का आउटपुट क्या होगा?
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
Error
B
Address of m
C
1
D
5
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 yfunction compares two numbers at a time and keeps the larger one. - After comparing all elements, the largest number
5is stored inm.
Output:
(D) 5reduce फ़ंक्शन यहाँ दी गई लिस्ट में सबसे बड़ी संख्या (Max) ढूँढ रहा है।
Correct Answer: D) 5