2.16. Functions

Functions in Python follow rules and syntax similar to most other languages: Functions are called using the functional operator ( ( ) ), functions must be declared before they are used, and the function type is the type of the value returned.

All arguments of function calls are made by reference, meaning that any changes to these parameters within the function affect the original objects in the calling function.

How to Declare a Function

							def
							function_name([ arguments]):
    "optional documentation string"
    function_suite
						

The syntax for declaring a function consists of the def keyword followed by the function name and any arguments which the function may take. Function arguments such as arguments above are optional, hence the reason ...

Get Core Python Programming 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.