Introduction to Python Programming

Get a good editor.

I use geany (sounds like genie). Available for Linux/Mac OS/Windows. Web site.

Spyder is a nice development environment.

Indentation is important.

Indentation is used to define loops, functions, etc. Can be any whitespace but you must be consistent.
a=1.0
numbers=[0,1,2,3]
for number in numbers:
	print number
print a,type(a)

Tuples, Lists, and Dictionaries

Tuples

Lists

Dictionaries

Using Python programs

Executing Python programs

  1. Create a file with the code
  2. Run it with the Python interpreter
    python codefile.py
    or in a Unix environment, set the code file executable (e.g., chmod 755 codefile.py) and the first line of the code pointing to the Python interpreter, e.g. codefile.py contains
    	#!/usr/bin/python
    	a=1.0
    	print a
    
    then you can just type
    	codefile.py

Procedural programs (like Fortran 77, BASIC, etc)

Object Oriented Programming in Python

OO Basics - Classes, Attributes, Methods, Subclassing, Inheritance, Overloading