Parameters in Function:
#
function defn
def
example(name):
print(name, "good morning")
example("Ganga")#function
call
example("Venu")
example("krishna")
If
we are passing the parameters (value/variable/data/information) to the
function.
It
is passed to the function which is specified in the parenthesis
We
can give any number of parameters to the function, we have to separate with
comma operator.
def
add(a,b):
c=a+b
print(c)
#reading
the input values
a=int(input("enter
a value"))
b=int(input("enter
b value"))
add(a,b)
#function call
we
can pass number of parameters to the functions
def
add(a,b):
c=a+b
# print(c)
return c
#reading the input values
a=int(input("enter
a value"))
b=int(input("enter
b value"))
print(add(a,b))
#function call
#defining the function
#call by reference
def
modify(b):
#print("list values are=",a)
#appending the values to the list
b.append(50)
b.append(60)
print(b)
a=[10,20,30,40]#list is created
#passing
immutable(list) object
modify(a)#function
call
Call by Reference:
Whatever
changes are done in the function, it is reflected to the actual parameter.
def
name(s):
s="Hello "+s
print(s)
s="How
are you"
name(s)
Related Video: https://youtu.be/JhTtHTdP2SA
Prev: A function return more than one value
No comments:
Post a Comment