Found an even number 8 Found an odd number 9 

## 4.5 pass Statements 

(continued from previous page) 

The pass statement does nothing. It can be used when a statement is required syntactically but the program requires no action. For example: 

>>> while True : ... pass # Busy-wait for keyboard interrupt (Ctrl+C) ... 

This is commonly used for creating minimal classes: 

>>> classMyEmptyClass : ... pass ... 

Another place pass can be used is as a place-holder for a function or conditional body when you are working on new code, allowing you to keep thinking at a more abstract level. The$_{pass}$is silently ignored: 

>>> def initlog(*args): ... pass # Remember to implement this! ... 

## 4.6 Defining Functions 

We can create a function that writes the Fibonacci series to an arbitrary boundary: 

>>> def fib(n): # write Fibonacci series up to n ... """Print a Fibonacci series up to n.""" ... a, b=0,1 ... while a <n: ... print(a, end ='') ... a, b=b, a+b ... print() ... >>> # Now call the function we just defined: ... fib(2000 ) 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 

The keyword$_{def}$introduces a function definition . It must be followed by the function name and the parenthesized list of formal parameters. The statements that form the body of the function start at the next line, and must be indented. 

The first statement of the function body can optionally be a string literal; this string literal is the function’s documen- tation string, or docstring . (More about docstrings can be found in the section Documentation Strings .) There are tools which use docstrings to automatically produce online or printed documentation, or to let the user interactively browse through code; it’s good practice to include docstrings in code that you write, so make a habit of it. 

The execution of a function introduces a new symbol table used for the local variables of the function. More precisely, all variable assignments in a function store the value in the local symbol table; whereas variable references first look in the local symbol table, then in the local symbol tables of enclosing functions, then in the global symbol table, and finally in the table of built-in names. Thus, global variables and variables of enclosing functions cannot be directly assigned a value within a function (unless, for global variables, named in a$_{global}$ statement, or, for variables of enclosing functions, named in a$_{nonlocal}$ statement), although they may be referenced. 

