How to return value from a function
Return value from a function
We can use return statement to return value from a function.
Values can be returned from functions using the return statement.
def square(x):# from www . ja v a2 s. com
return x*x
print square(3)
def test():
print 'This is printed'
return
print 'This is not'
x = test()
The code above generates the following result.
As you can see, the second print statement is skipped.
Return a tuple.
def quadcube (x):
return x**2, x**3
# ww w . j a va 2 s. co m
a, b = quadcube(3)
print a
print b
The code above generates the following result.