Introduction to Python

The best way to learn how to program is to do something useful, so this introduction to Python is built around a common scientific task: data analysis.

Our real goal isn’t to just to teach Python, but to teach you the basic concepts that all programming depends on. We use Python in our lessons because:

  • We have to use something for examples
  • It’s free, well-documented, and runs almost everywhere
  • It has a large (and growing) user base among scientists
  • Experience shows that it’s easier for novices to pick up than most other languages.

But the two most important things are to use whatever language your colleagues are using, so that you can share your work with them easily, and to use that language well.

Prerequisites:

In order to complete the tutorial you should be familar with:

  • The linux command line

If you are looking for the worksheets or their solutions click on the links.

Schedule:

If this is your first time using Python, the following lessons should take you through all you need to know about it's basic syntax, as well as some of it's programming ethos.

Time Episode Description
0:00 Setup Get set(up)
0:10 Getting Started with Python Some first programs
0:30 Variables and Assignment How do we store and access data?
0:50 Jupyter Notebooks What's in a Jupyter notebook?
1:15 Datatypes and Conversion How does python store data?
1:40 Lists How can we store lists of data?
2:10 Looping How do we efficiently access data stored in lists?
2:40 Making Choices If then what or else
3:05 Creating Functions Functions contain modular blocks of code for reuse

For those who work fast or simply want to know more, there are three more lessons which explore how we can add additional functionality to Python through libraries, use Python to interact with other files, and run Python scripts from the command line.

Time Lesson Description
3:30 Libraries Avoid reinventing the wheel
3:50 Reading Data How do we read data into python?
4:20 Command-Line Programs Combine all we've learnt to write a program we can run in the command line