Source Code:
(back to article)
# Adding two numbers using Lambda sum = lambda x, y: x + y print(sum(10, 20)) # Output: 30 # Finding the square of a number using Lambda square = lambda x: x ** 2 print(square(5)) # Output: 25 # Sorting a list of numbers using Lambda numbers = [4, 1, 3, 6, 7, 2] sorted_numbers = sorted(numbers, key=lambda x: x) print(sorted_numbers) # Output: [1, 2, 3, 4, 6, 7]
Result:
Report an issue