Python Programming

Module aims

Python is one of the fastest growing programming languages due to its readability and flexibility and is widely used in industry today. Python's rise in popularity is also due to the broad set of libraries available for Machine Learning and Data Science.

The course aims to teach students the fundamentals of Python and several packages specifically designed for Machine Learning and Data Science. The aims of the course are:

  • to introduce the fundamental features of the Python programming language to students;
  • to enable students to write procedural, object oriented and functional programs in Python;
  • to introduce some of the most widely used modules from the Python standard library;
  • to help students gain a good understanding of, and ability to use, common design patterns;
  • to introduce several widely used and foundational Python Machine Learning and Deep Learning libraries;
  • to present key Python tools and allow students to apply them in order to become effective Python programmers.

Learning outcomes

After the module, students will be able to:

  1. devise and evaluate programs using standard programming constructs in Python (LO1);
  2. assess and write procedural, object oriented and functional code in Python (LO2);
  3. create, select, and apply appropriate techniques and relevant library software in Python to solve a given problem (LO3);
  4. structure and reorganize Python programs with appropriate design patterns (LO4);
  5. adapt, combine, and apply relevant pre-processing steps and standard Machine Learning algorithms for classification tasks (LO5).

Module syllabus

  • Intro to (Python) programming
    • Introduction to Linux (terminal, ssh)
    • running Python scripts (interactive sessions, command-line, redirecting output)
  • Basic language elements
    • variables and data types (numbers, lists, sets, tuples, strings, dictionaries)
    • control flow
    • comprehension (list, set, dictionary)
    • main method
    • string manipulation
  • Functions (arguments, recursion)
  • Object-oriented programming
    • classes
    • objects
    • methods
    • attributes
    • inheritance
    • encapsulation
    • polymorphism
  • Scripts, modules, packages
  • Standard library (operating system functionality, persistence, regular expressions, concurrency, argparse)
  • Functional programming ((built-in) higher order functions)
  • File manipulation
    • file handling
    • input/output
    • JSON
    • CSV
  • Exception handling
  • Testing in Python
  • Data processing and Machine Learning/Deep Learning concepts:
    • Numpy (arrays, array manipulation)
    • Pandas (data analysis and manipulation)
    • Scikit-learn (training and evaluating classifiers)
    • Keras (training deep learning classifiers)
  • Design practices (Dependency injection, idiomatic Python, refactoring)

Teaching methods

1st week of 2h lectures and 4h labs.
7 weeks of 4h lectures and 6h labs.
New topic(s) each week supported by laboratory sessions.
Wrap up lecture and a revision lecture at the end of the course.
Mock test at the end of the course to prepare for the exam.


There will be 2 computer-based programming exercises in Python for students to practice the topics that have been covered during the course. Students will work independently to solve the exercises having 2 weeks to complete each coursework. It should be possible to complete each coursework in the allocated lab sessions.
The first coursework will focus on the application of basic language elements and object-oriented programming to solve various tasks, making use of standard programming constructs and relevant library software. Learning outcomes LO2 and LO3 will be assessed. The coursework will be set in week 3.
The second coursework will focus on data processing and using Machine Learning/Deep Learning libraries to solve classification problems. Learning outcome LO5 will be assessed. The coursework will be set in week 6.
The computer-based exercises will be submitted via LabTS which allows for auto-testing to pick up basic syntax errors. Submissions will then be marked by TAs to give detailed feedback. The marked exercises will be returned within 2 weeks of the submission deadline.
There will be a 2h computer-based exam in the first week of the spring term, intended to cover all learning outcomes.

Detailed written feedback will be provided by teaching assistants for the coursework assignments. The lecturer and teaching assistants will be available to answer questions and provide direct verbal feedback during the laboratory sessions.

Reading list

Core reading

Supplementary reading

Module leaders

Dr Josiah Wang