Appendix B
Introduction to Python
Python is a programming language that was initially released in 1991 by Guido Van Rossum,
and which has since become deservedly popular for its elegance, ease of use, readability,
portability, and extensibility. It marks code blocks using indentation, instead of parentheses
(such as C), or “begin,” “end” words (such as MATLAB). Since its inception Python has
matured, is used worldwide for enterprise systems as much as for elementary teaching, and
there are a vast number of specialized libraries—over 54,000 at the time of writing—which
support particular programming tasks. Some of the most richly developed and most used
libraries include:
numpy “Numerical Python,” routines for array manipulation and high-
level functions for operating on arrays.
scipy “Scientific Python,” which includes modules for optimization, nu-
merical analysis, signal and image processing, and differential
equation solvers.
matplotlib
A plotting library, which includes an interface
pyplot
designed
to emulate the plotting tools of MATLAB.
Python’s standard library is rich and full-featured, and allows the handling of many differ-
ent data types, mathematics, Internet protocols, file and data handling, system interfaces,
multimedia, and graphics interface design.
Unlike MATLAB or Octave, not all of Python’s f unctions are available to the user at
the start; many functions have to be “imported”, either by importing their library or by
importing just the f unctions needed. This makes the namespace very manageable, and can
allow for different functions sharing the same name.
Python has many interfaces. IDLE (“Integrated Development Environment”) is bundled
with the language, and may be considered a simple and uncluttered Python shell. IPython
is an enhanced shell that includes syntax highlighting, automatic indentation, inline graph-
ics, and many other enhancements. Spyder provides a graphics development environment,
similar in some ways to that of MATLAB or Octave, and with integration of numpy, scipy,
matplotlib, and iPython. There are numerous other interfaces, some open source, others
proprietary. Unlike most programming systems, where the choice is betwee n a graphics
interface or a command line interface, the Python user is sp oiled for choice.
Figure B.1 shows two standard development environments: iPython and Spyder. IPython
has been configured to produce graphics “inline”; this is just one of many configuration op-
tions. Note that Spyder includes the iPython enhanced shell within it (and support for
other consoles), as well as a variable and file browser, integrated editor, and interface to the
Python debugger.
505