Programs
1. WAP tofind the factorial of a number provided
by user using Recursion.
2. WAP to print the fibonacci Series upto n terms,
where n is provided by user.
3. WAP to find the GCD (or HCF) using Recursion.
4. WAP to input a string from the user and check
whether it is palindrome or not.
7.
Lambda Functions orAnonymous Functions
Those Functions which does not have any name is called
Anonymous Functions. In Python, this can be achieved by using
keyword lambda, that’s why it is also called Lambda Functions.
They are not declared in the standard manner by using the def
keyword
Lambda forms can take any number of arguments but return
just one value in the form of an expression. They cannot
contain commands or multiple expressions.
8.
Syntax
The syntaxof lambda functions contains only a single
statement, which is as follows:
lambda arg1 ,arg2,.....argn:expression
Example:
add = lambda a, b : a + b
print("Value of total : ", add( 10, 20 ) )
9.
Non-Anonymous Function AnonymousFunction
def square(x):
return x*x
n=int(input(“Enter the Number”))
print(square(n))
a=lambda x:x*x
n=int(input(“Enter the Number”))
print(a(n))
10.
Lambda Function withmap() function
l=list(map(int,input().split()))
Similarly
L1=[1,2,3,4]
L2=list(map(lambda x:x*x,L1))
print(L2)
Output:[1,4,9,16]
11.
Lambda Function withfilter() function
L1=[1,2,3,4]
L2=list(filter(lambda x:x%2==0,L1))
print(L2)
Output:[2,4]
12.
Lambda Function withreduce() function
import functools
L1=[1,2,3,4,5,6,7,8,9,10]
L2=functools.reduce((lambda a , b : a+b), L1)
print(L2)
Output:55