- 2

# What is the output of the following program : y = 8 z = lambda x : x * y print z(6)

explain plz

5 Answers

+ 7

It is a SyntaxError. You need parentheses for the function print(). So the last line should be:
print(z(6))
Other than that the result is 48.
Why?
First the number 8 is assigned to the variable y.
Then lambda defines a function withe the argument x.
The function now simply adds the argument and multiplies it with the variable y which is 8.
We store this function in a variable.
Now we print the output of z with the argument 6. As z contains the function we defined earlier it gets called with the argument 6.
So now it calculates x (that what we specified in the last line) times y (which is 8).
Output will be 6 * 8.
Put simply:
• First we have number 8.
• We define a function that calculates whatever we specify later as x times 8.
• Then we print the output of the function. (It gets called by the variable z)
• 6 gets in the place of x and so 6 is multiplied with 8.

+ 1

48

0

the lambda express means a function that takes x as param and return x*y as result

0

48:
6 will be pass to lambda and uses as x and then we have x*y which y is 8
so we have x*8
which x is 6
so 6*8= 48

0

. What is the output of the following for loop and range() function
for num in range(-2,-5,-1): print(num, end=", "