DekGenius.com
[ Team LiB ] Previous Section Next Section

Chapter 12. Function Basics

In Part III, we looked at basic procedural statements in Python. Here, we'll move on to explore a set of additional statements that create functions of our own. In simple terms, a function is a device that groups a set of statements, so they can be run more than once in a program. Functions also let us specify parameters that serve as function inputs, and may differ each time a function's code is run. Table 12-1 summarizes the primary function-related tools we'll study in this part of the book.

Table 12-1. Function-related statements and expressions

Statement

Examples

Calls

myfunc("spam", ham, "toast")

def, return, yield

def adder(a, b=1, *c): return a+b+c[0]

global

def function( ): global x; x = 'new'

lambda

funcs = [lambda x: x**2, lambda x: x*3]

    [ Team LiB ] Previous Section Next Section