8.9. Summary

This chapter introduced user-defined functions. Functions are useful because functions are reusable pieces of code. All functions have names. Some functions take input arguments and produce output. Functions in Python are defined with the keyword def. You learned how to create functions with default arguments. You also learned the difference between positional arguments and keyword arguments. Positional arguments must be included in the proper order. Keyword arguments must include the keyword name and an equals sign. You learned how to call functions which are contained in a different file than the file that calls the function. One section of the chapter reviewed how docstrings work in Python functions and the results of calling Python’s help() on a function that contains a docstring. At the end of the chapter you learned how to pass lists and dictionaries to Python functions.

8.9.1. Key Terms and Concepts

function

function definition

arguments

default arguments

positional arguments

keyword arguments

keyword

output

docstring

return

.py-file

import

syntax

comments

documentation

iterable

8.9.2. Python Commands

Command

Description

def

define a function

return

define the expression or value a function outputs

import

import a module or .py file

from

import a function or class from a module or .py file

as

name an alias for a function, method or class

"""   """

define a docstring