How do I learn python and why?

Python is an interpreted programming language.  It is very good at string manipulation and interactions with the operating system.  Because it is interpreted on the fly, it is much slower than higher level languages like C++.

Most particle physicists find that they need both a scripting language like python to control their work flow and a high level language like C or C++ to do the actual work.

I’ve found that python is easy to learn on your own. You need two things – a good manual and python on your machine.

Getting python

On Mac’s and PC’s you can just download a binary installation from the python.org website. You may need to install the free C++ compiler for your machine to get this to work.

On Linux, it is likely that python is already installed. If not you can also do a download but installation is a bit more hands-on. Follow the instructions and it should work.

The good manual

I recommend Learning Python by Mark Lutz.  You don’t actually need the latest edition and the older ones are shorter.

My students (being short of cash) swear by the online tutorials at

docs.python.org/tutorial/

You will also find that the Python Language Reference is invaluable for finding instructions on particular topics.

Getting Started

I’ve found that beginners often get hung up on how to start.  Lutz starts you out on the python command line which can be frustrating if you are a lousy typist.

Instead I suggest writing short python programs and executing them.  That way you have a record of what you have done and can iterate fixing things.

Running python

On Mac’s and PC’s, python comes with a great editor called IDLE which is allows you to edit a program and run it by hitting F5.

On linux, I haven’t found a similar program but you can invoke your program by typing

python <myprogram.py>

Summary

With python, a good manual and an editor like IDLE you are ready to go.

It is also very useful to look/steal at other people’s code. Why reinvent the wheel when it is open source.

Unknown's avatar

About Professor X

I'm a high energy physicist at a major research university.

Leave a comment