This repo is a collection of Python scripts designed to teach the basics of the language.
Provided that python is installed on your machine, you should be able to run any of these scripts by typing
python scriptname.py
With the exception of boid.py
and vector.py
, as these define Objects (see below).
If you're using a Mac, it's best to install your own python distribution rather than using the native version (I recommend Anaconda, as it will help you install lots of useful modules as well) The scripts are best considered in the following order:
helloworld.py
- the standard first script to run in a new language,counter.py
- a script showing you how to use if statements and loops, and how to import a modulesequences.py
- a script showing you how to manipulate datasets (lists, tuples, strings and dictionaries)filecheck.py
- a script showing basic file reading and writing, as well as exceptions (i.e. how to catch your own mistakes)plotting.py
- a script showing how to usenumpy
andmatplotlib
to read data and make plotsflocking.py
- a script that runs a flocking simulation, using object oriented programming (objects defined inboid.py
andvector.py
)
This should be enough to begin basic Python programming. It's definitely worth checking out the numpy
and matplotlib
modules to find all sorts of functions (that you'll never have to write yourself!) to do all kinds of scientific programming.