30 Python Programming Questions on Lambda Functions
Q 1. Define a lambda function that returns the square of a number.
Input: 5
Expected Output:
25
Q 2. Define a lambda function that adds two numbers.
Input: 3, 4
Expected Output:
7
Q 3. Define a lambda function that returns the maximum of two numbers.
Input: 10, 20
Expected Output:
20
Q 4. Define a lambda function that returns whether a number is even.
Q 5. Define a lambda function that concatenates two strings.
Input: "Hello", " World"
Expected Output:
Hello World
Q 6. Define a lambda function that returns the first character of a string.
Input: Python
Expected Output:
P
Q 7. Define a lambda function that returns the length of a list.
Input: [1, 2, 3, 4]
Expected Output:
4
Q 8. Define a lambda function that multiplies three numbers.
Input: 2, 3, 4
Expected Output:
24
Q 9. Define a lambda function that returns the last element of a list.
Input: [1, 2, 3, 4]
Expected Output:
4
Q 10. Define a lambda function that returns whether a number is greater than 10.
Q 11. Define a lambda function that returns the absolute value of a number.
Q 12. Define a lambda function that converts a string to uppercase.
Input: hello
Expected Output:
HELLO
Q 13. Define a lambda function that checks if a string contains the letter 'a'.
Input: banana, berry
Expected Output:
True
False
Q 14. Define a lambda function that returns the sum of squares of two numbers.
Input: 3, 4
Expected Output:
25
Q 15. Define a lambda function that filters out odd numbers from a list.
Input: [1, 2, 3, 4, 5]
Expected Output:
[1, 3, 5]
Q 16. Define a lambda function that squares each number in a list.
Input: [1, 2, 3, 4]
Expected Output:
[1, 4, 9, 16]
Q 17. Define a lambda function that returns a list of tuples where each tuple is (index, value) of elements in a list.
Expected Output:
[(0, 'a'), (1, 'b'), (2, 'c')]
Q 18. Define a lambda function that returns the first n even numbers.
Input: 5
Expected Output:
[0, 2, 4, 6, 8]
Q 19. Define a lambda function that converts a list of strings to their lengths.
Input: "Python", "Java", "C++"
Expected Output:
[6, 4, 3]
Q 20. Define a lambda function that returns the difference between two numbers.
Input: 10, 4
Expected Output:
6
Q 21. Define a lambda function that returns the reverse of a string.
Input: Python
Expected Output:
nohtyP
Q 22. Define a lambda function that multiplies each element in a list by 2.
Input: [1, 2, 3, 4]
Expected Output:
[2, 4, 6, 8]
Q 23. Define a lambda function that returns the maximum value in a list.
Input: [10, 20, 30, 40]
Expected Output:
40
Q 24. Define a lambda function that checks if a number is positive.
Q 25. Define a lambda function that filters out strings longer than 3 characters from a list.
Input: ["cat", "elephant", "dog", "horse"]
Expected Output:
['elephant', 'horse']
Q 26. Define a lambda function that returns the sum of digits of a number.
Input: 123
Expected Output:
6
Q 27. Define a lambda function that returns the nth element of a list.
Q 28. Define a lambda function that computes the average of a list of numbers.
Input: [10, 20, 30]
Expected Output:
20.0
Q 29. Define a lambda function that returns the first n multiples of a number.
Input: (3, 4)
Expected Output:
[3, 6, 9, 12]
Q 30. Define a lambda function that sorts a list of tuples by the second element.
Input: [(1, 3), (2, 2), (3, 1)]
Expected Output:
[(3, 1), (2, 2), (1, 3)]
Bikki Singh
Hi, I am the instructor of TechnoVlogs. I have a strong love for programming and enjoy teaching through practical examples. I made this site to help people improve their coding skills by solving real-world problems. With years of experience, my goal is to make learning programming easy and fun for everyone. Let's learn and grow together!