Mark Foley's DIT Lecture Notes:
Python Programming

Programming using Python. Offered in programme DT249 Stage 1 as Programming & Algorithms 1 and Programming & Algorithms 2. and in programme DT211 Year 2 as Object Oriented Programming. Click the highlighted links for further details. These are the "official" syllabi which don't change too often. The module as delivered will be adjusted to reflect advances in the body of knowledge and the technologies associated with the subject.

Develop programming and problem solving skills, progressing from procedural to object‐oriented programming

This page provides access to notes and other material that we'll be using in class. The module content is built around the idea of "topics". These correspond roughly but not exactly to weeks. In other words, we may not finish a topic in any given week or we may cover more than one topic in any given week.

This list will be expanded as the semester progresses.


  1. Introduction to Python
  2. Review of Programming and Computer Science in general
  3. Variables, operators, objects and types
  4. Control, selection and repetition
  5. Algorithms and program development
  6. String manipulation in Python
  7. Files and exceptions
  8. Functions and data structures
  9. More data structures: lists, tuples, dictionaries and sets
  10. Advanced program development and problem-solving
  11. Classes, objects and OOP
  12. Object methods
  13. Encapsulation, inheritance and polymorphism
  14. Python and other OOP languages
  15. Overloading
  16. Program development with classes
  17. Being a better programmer
  18. Testing and test-driven development
  19. Recursion
  20. Iterators, generators and decorators
  21. Object serialization

Reading List

The Practice of Computing Using Python (2nd Ed) William F. Punch, Richard Enbody
Publisher: Addison-Wesley, 2 edition (2012), ISBN: 978-0132805575

This is the main course text. We will be mostly using material from this, at least initially. We will also be using material from other sources including, but not limited to, those listed below.

Python Programming In Context Bradley N. Miller, David L. Ranum
Publisher: Jones & Bartlett Learning; 2 ed (2013) ISBN: 978-1449699390

Think Python How to Think Like a Computer Scientist Allen Downey
Version 1.1.24+Kart [Python 3.2]
Publisher: Green Tea Press

There is a free download of this book available. make sure that you download the version for Python 3.

Dive Into Python 3 Mark Pilgrim
Publisher: Apress; 2 ed (2009) ISBN: 978-1430224150

There is also a free download of this book available.

Other Readings and Resources

This section contains selected links that you should read. These generally cover topics that are worth discussing in class but that we don't have time to consider in a detailed lecture format.

On the myth of "plain" text and character encoding schemes

There is no such thing as plain text. This statement has implications for how we think about text - characters (an abstract concept) and representation (how this abstraction is represented in bits and bytes in a computer).

Why are indexes zero-based?

Beginning students of programming often wonder why we don't start indexes for arrays, lists and suchlike from one. After all, we count from one so it would seem more intuitive. The following few articles might help to clarify the reasons why we use 0 as a start point and why this might be actually a good idea.

Source Code Management a.k.a Version control

What is version control, and why should you care? Version control is a system that records changes to a file or set of files over time so that you can recall specific versions later. Any type of file on a computer can be placed under version control but, in our case, it is particularly useful for software source code.

If you want to keep every version of a file (which you certainly would), it is very wise to use a Version Control System (VCS). A VCS allows you to: revert files back to a previous state, revert the entire project back to a previous state, review changes made over time, see who last modified something that might be causing a problem, who introduced an issue and when, and more. Using a VCS also means that if you screw things up or lose files, you can generally recover easily. In addition, you get all this for very little overhead.

The VCS of choice in the School of Computing (and in many other places) is git. Material in the preceding paragraphs was taken and modified from the git website.

It is strongly recommended that you look at the following links, in order listed.

Visualising your code with Python Tutor

Python Tutor ( is a free educational tool created by Philip Guo that helps students overcome a fundamental barrier to learning programming: understanding what happens as the computer executes each line of a program's source code. Using this tool, a teacher or student can write a Python program in the Web browser and visualize what the computer is doing step-by-step as it executes the program.

This is a very useful tool that you should check out. It is, however, limited as to the size of progarm it can handle. Also, it won't cope with file I/O.