When we define a function only gives it a name, specifies the parameters that are to be included in the function and structures the blocks of code and refer to that value .In calling function you have to define specifies parameters.For example you can see below code.
# Function definition is here
def printfindnerd( str ):
"This prints a passed string into this function with findnerd string name"
print str
return;
# Now you can call printme function and define it.
printme("we are first call to user defined function!")
printme("And again we are second call to the same function")
Output
we are first call to user defined function!
And again we are second call to the same function
Pass by reference and value->
In pass by reference and value we have to define parameters (arguments) in the Python language are passed by reference.tAnd we can change what a parameter refers to within a function, the change also reflects back in the calling function and set the value. For example you can see below code.
def demome( mylist ):
"This changes a passed list into this function and set the value"
mylist.append([1,2,3,4,5,6]);
print "Values inside the function: ", mylist
return
# Now you can call changeme function
mylist = [10,20,30,40];
changeme( mylist );
print "Values outside the function: ", mylist
Output-> Values inside the function: [10, 20, 30,40, [1, 2, 3, 4,5,6]]
Values outside the function: [10, 20, 30,40, [1, 2, 3, 4,5,6]]
0 Comment(s)