Function with an argument and return type

Sometimes, it may be necessary to return any specific datatype or value from a function which takes any arbitrary number of arguments. Let's evaluate this scenario with an example:

def sum(a, b): 
c = a+b
return c
x = 10
y = 50
print "Result of addition ", sum(x,y)

Here, we define the function, which accepts two arguments and the body evaluates their sum with return type as value of the sum, which is denoted by the return c statement. We then call the function in the print statement and pass the value of variable x and variable y. This will give us the output as shown next:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.29.119