This lesson is being piloted (Beta version)

Object Oriented Programming in Python

Object-oriented programming is a popular technique for structuring software, particularly in larger software projects being developed by larger groups of people. In this lesson we will use the tools for object-oriented programming provided by the Python programming language to learn how it can be used to write modular, reusable components for research software.


This lesson assumes some level of familiarity with the Python programming language. If you have not previously used Python, and in particular if you are unfamiliar with programming in general, then we would recommend reading through Software Carpentry’s introductory Programming with Python lesson before embarking on this one.


Setup Download files required for the lesson
00:00 1. Objects in Python What are objects in Python?
What is a class or type?
Can objects belong to more than one class?
How can objects be created from a class?
00:35 2. Writing classes How are classes written in Python?
What do methods look like?
How can a class customise how its instances are constructed?
01:20 3. Inheritance How can classe relationships where one represents a specific subset of another be represented?
How can functionality on one class be overridden or extended by its children?
02:00 4. Decorators, class methods, and properties What is a decorator?
How do I tag methods as being applicable to a class rather than an instance?
How can I add logic to process changes to instance variables?
02:45 5. Special methods How can classes allow their instances to work with standard Python operators?
How can classes allow their instances to behave like iterables or collections?
How can classes allow their instances to be called like functions?
03:25 6. Duck typing and interfaces How does Python decide what you can and can’t do with an object?
When is inheritance not appropriate?
What alternatives are there to inheritance?
03:50 Finish

The actual schedule may vary slightly depending on the topics and exercises chosen by the instructor.