© Sloan Kelly  2019
Sloan KellyPython, PyGame, and Raspberry Pi Game Developmenthttps://doi.org/10.1007/978-1-4842-4533-0_12

12. User-Defined Functions

Sloan Kelly1 
(1)
Niagara Falls, ON, Canada
 

A user-defined function allows you to package and name several lines of code and reuse those lines of code throughout your program. All you must do is call the name you’ve given your function.

What Is a Function?

A function in Python can be used to perform a simple task, and as such is just a mnemonic or special name given to a collection of lines. You can also optionally send values into a function as parameters or return a value from a function. Only one value can be returned from a function, but that value can be a tuple.

Format of a Function

The following ...

Get Python, PyGame, and Raspberry Pi Game Development 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.