check even odd by lambda function in python by R4R Team

Lambda function-
-In Python, anonymous function means that a function is without a name. As we already know that def keyword is used to define the normal functions and the lambda keyword is used to create anonymous functions.

Syntax-

lambda argument:expression

-So for check the number is even or odd, we pass one argument, or in expression we write a condition for even odd checking.


program-

#lambda function with recursion
check=lambda x: 1 if x%2==0 else 0

print("Enter number to check even or odd")
if check(int(input())):
print("Even")
else:
print("Odd")


output-

Enter number to check even or odd
3
Odd
Enter number to check even or odd
4
Even


-In this program, we have a lambda function i.e. lambda x: 1 if x%2==0 else 0, which are able to check number is even or odd. so we take a input of number and pass as argument in this function by
-check(int(input()))




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!