Simple Python Lambda Function - Questions and Answers
Q1: Write a lambda function to add 5 to a number.
add_5 = lambda x: x + 5
print(add_5(10)) # Output: 15
Q2: Write a lambda function to subtract 3 from a number.
subtract_3 = lambda x: x - 3
print(subtract_3(8)) # Output: 5
Q3: Write a lambda function to multiply a number by 2.
multiply_2 = lambda x: x * 2
print(multiply_2(6)) # Output: 12
Q4: Write a lambda function to divide a number by 2.
divide_2 = lambda x: x / 2
print(divide_2(10)) # Output: 5.0
Q5: Write a lambda function to find the square of a number.
square = lambda x: x * x
print(square(4)) # Output: 16
Q6: Write a lambda function to find the cube of a number.
cube = lambda x: x * x * x
print(cube(3)) # Output: 27
Q7: Write a lambda function that returns True if a number is greater than 10.
greater_than_10 = lambda x: x > 10
print(greater_than_10(15)) # Output: True
print(greater_than_10(5)) # Output: False