Chapter 35 User-Defined Subprograms

35.1 Subprograms that Return Values

In Python and many other computer languages, a subprogram that returns values is called a function. There are two categories of functions in Python. There are the built-in functions, such as int(), float(), and there are the user-defined functions, those that you can personally write and use in your own programs.

The general form of a Python function that returns one or more values is shown here.

def name([arg1, arg2, arg3, …]):
A statement or block of statements
 
return value1 [, value2, value3, … ]

where

name is the name of the function.
arg1, arg2, arg3, … is a list of arguments (variables, lists etc.) used to pass values from the caller to the function. There can ...

Get Python and Algorithmic Thinking for the Complete Beginner now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.