Chapter 4. Functions

Chapter 4. Functions

In the last chapter, 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, functions are a device that groups a bunch of statements, so they can be run more than once in a program. Functions also let us specify parameters, which may differ each time a function's code is run. Table 4.1 summarizes the function- related statements we'll study in this chapter.

Table  4.1. Function-Related Statements

Statement

Examples

Calls

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

def , return

 def adder(a, b, c=1, *d): return a+b+c+d[0] 
 global 
 def function(): global x, y; x = 'new' 


Learning Python
Learning Python: Powerful Object-Oriented Programming
ISBN: 0596158068
EAN: 2147483647
Year: 1999
Pages: 156
Authors: Mark Lutz

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net