Using the if statement ................................................................................ 24
How It Works ........................................................................................... 25
The while statement ........................................................................................... 26
Using the while statement ........................................................................... 26
The for loop ..................................................................................................... 27
Using the for statement .............................................................................. 27
The break statement ........................................................................................... 28
Using the break statement ........................................................................... 28
The continue statement ....................................................................................... 30
Using the continue statement ....................................................................... 30
Summary ......................................................................................................... 30
7. Functions ............................................................................................................. 32
Introduction ..................................................................................................... 32
Defining a Function ................................................................................... 32
Function Parameters .......................................................................................... 32
Using Function Parameters ......................................................................... 33
Local Variables ................................................................................................ 33
Using Local Variables ................................................................................ 34
Using the global statement .......................................................................... 34
Default Argument Values ................................................................................... 35
Using Default Argument Values .................................................................. 35
Keyword Arguments .......................................................................................... 36
Using Keyword Arguments ......................................................................... 37
The return statement .......................................................................................... 37
Using the literal statement ........................................................................... 38
DocStrings ....................................................................................................... 38
Using DocStrings ...................................................................................... 39
Summary ......................................................................................................... 40
8. Modules ............................................................................................................... 41
Introduction ..................................................................................................... 41
Using the sys module ................................................................................. 41
Byte-compiled .pyc files ..................................................................................... 42
The from..import statement ................................................................................. 42
A module's __name__ ........................................................................................ 42
Using a module's __name__ ........................................................................ 43
Making your own Modules ................................................................................. 43
Creating your own Modules ........................................................................ 43
from..import ............................................................................................. 44
The dir() function .............................................................................................. 45
Using the dir function ................................................................................ 45
Summary ......................................................................................................... 46
9. Data Structures ...................................................................................................... 47
Introduction ..................................................................................................... 47
List ................................................................................................................ 47
Quick introduction to Objects and Classes ..................................................... 47
Using Lists .............................................................................................. 47
Tuple .............................................................................................................. 49
Using Tuples ............................................................................................ 49
Tuples and the print statement ..................................................................... 50
Dictionary ....................................................................................................... 51
Using Dictionaries ..................................................................................... 51
Sequences ........................................................................................................ 53
Using Sequences ....................................................................................... 53
References ....................................................................................................... 54
Objects and References .............................................................................. 55
More about Strings ............................................................................................ 56
String Methods ......................................................................................... 56
Summary ......................................................................................................... 57
A Byte of Python
v