InterviewSolution
| 1. |
Explain “The returnStatement” with example. |
|
Answer» The statement return [expression] exits a function, optionally passing back an expression to the caller. A return statement with no arguments is the same as return None. All the above examples are not returning any value, but if you like you can return a value from a function as follows : #!/usr/bin/py thon # Function definition is here def sum(arg1,arg2): # Add both the parameters and return them. ” total=arg1+arg2 print “Inside the function : “, total return total; # Now you can call sum function total=sum(10,20); print “Outside the function total This will produce the following result: Inside the function : 30 Outside the function : 30 |
|