Professional Documents
Culture Documents
l[2] = 'sai'
try:
t[2] = 'sai'
except TypeError:
print(l)
print(t)
overwrite(l,t)
Default Parameters
#Sample program using default parameters
def add(a=3,b=2):
c=a+b
print(c)
add()
Error: Non-default arguments cannot follow default arguments
def add(a=3,b):
c=a+b
print(c)
add()
#sample program of one parameter receiving multiple
arguments
def add(*a):
tot=0
for i in range(len(a)):
tot=tot+a[i]
add(111,111,111)
Debugging of the above program for Local and global Variables
a(111,111,111) has become a local variable not a global variable along with tot
and i
Recursive Functions: Calling a function in itself is called Recursive functions
#sample program on finding the factorial of given number using
Recursive functions
def fact(a):
if(a!=0):
return a*fact(a-1)
else:
return 1
n=int(input('enter the value of n '))
k=fact(n)
INNER FUNCTIONS
INNER FUNCTIONS USING DEBUGGER
NESTED FUNCTIONS
NESTED FUNCTIONS USING DEBUGGER
Multiple Return Of Values
Sending default parameters to User Defined Function's
Using Default Arguments(y=None)
print (x, y, z)
if n==1:
return 'end'
else:
a,b=b,a+b
k=fib(n,a,b)
k = list(filter(lambda x:x%2==0,ls))
print(k)