Python lambda()
Write a program in Python to calculate the value of the following expression by using lambda function.
The expression is -
(x * 10) + (y / 2) * z
Solution
Lambda is an anonymous function that contains any number of arguments, but only one expression. This function is defined without a name.
Syntax of Python lambda()
lambda arguments: expression
Here, the arguments can be any numbers, but the expression should be only one.
This is the following solution to calculate the value of the given expression by using lambda function.
print("Please enter the values of x, y and z")
x = input()
y = input()
z = input()
expr = lambda x, y, z: (x * 10) + (y / 2) * z
print expr(x, y, z)
Output of the above code
Related Articles
Python program for Prime NumberOdd Even Program in Python
Python program to convert Celsius to Fahrenheit
Python Convert XML to CSV
Python Text to Speech
Python send mail to multiple recipients using SMTP server
How to generate QR Code in Python using PyQRCode
Python programs to check Palindrome strings and numbers
CRUD operations in Python using MYSQL Connector
Fibonacci Series Program in Python
Python File Handler - Create, Read, Write, Access, Lock File
Python convert XML to JSON
Python convert xml to dict
Python convert dict to xml