Python by Swaroop C H - HTML preview

PLEASE NOTE: This is an HTML preview only and some elements such as links or page numbers may be incorrect.
Download the book in PDF, ePub, Kindle for a complete version.

Using the literal statement

Example 7.7. Using the literal statement

#!/usr/bin/python
# Filename: func_return.py def maximum(x, y):
if x > y:
return x else:
return y print maximum(2, 3)

Output

$ python func_return.py 3

How It Works

Themaximum function returns the maximum of the parameters, in this case the numbers supplied to the function. It uses a simpleif..else statement to find the greater value and then returns that value.

Note that a return statement without a value is equivalent toreturn None.None is a special type in Python that represents nothingness. For example, it is used to indicate that a variable has no value if it has a value ofNone.

Every function implicitly contains a return None statement at the end unless you have written your ownreturn statement. You can see this by runningprint someFunction() where the function someFunction does not use thereturn statement such as:

def someFunction(): pass

 

Thepass statement is used in Python to indicate an empty block of statements.