Lambda Functions: What will the output of the following program be?


func = (lambda x, y, z: x if x > y & x > z else y if y > z else z)
print(chr(func(ord('b'), ord('a'), ord('C'))))
  • 'a'
  • 'b'
  • 'C'
  • 99
  • 98

The lambda function defined in the code will find the largest of x, y, z. Now the arguments passed to the function are ord('b'), ord('a'), ord('C') which evaulate to 98, 97, and 67 respectively. Now of these 3, 98, i.e. ord('b') is the highest. And 98 is again converted to alphabet using the function chr(). Hence, you get the output as 'b'.