Loading video player…

Class Concepts: Object-Oriented Programming in Python (Overview)

Python includes mechanisms for doing object-oriented programming, where the data and operations on that data are structured together. The class keyword is how you create these structures in Python. Attributes are the data values, and methods are the function-like operations that you can perform on classes. In this course, you’ll explore writing code using class and its associated attributes and methods.

In this video course, you’ll learn about:

  • Why you write object-oriented code
  • How to write a class
  • What attributes and methods are
  • How to use the descriptor protocol

This course is the first in a three-part series. Part two covers how to write reusable hierarchies of classes using inheritance, while part three dives deeper into the philosophy behind writing good object-oriented code.

Download

Sample Code (.zip)

5.2 KB
Download

Course Slides (.pdf)

1013.9 KB

00:00 Welcome to Class Concepts: Object-Oriented Coding in Python. My name is Christopher, and I will be your guide.

00:08 That title is a bit of a mouthful because this is a three-part course. Releasing all three parts takes time, so depending on when you’re doing this course, the other two parts may still be in progress.

00:20 Links in the notes below will be provided to the other two parts as they become available. The purpose of this course is to teach you about object-oriented coding in Python.

00:30 The first part introduces you to the basic object-oriented coding structures, like the class keyword, how you use it to write classes, and how you associate attributes and methods (that’s OO speak for data and operations) with the class.

00:45 Part two teaches you how to use inheritance, a mechanism for structuring classes based on other classes. This mechanism allows you to create hierarchies of classes to correspond to real-world items, as well as providing a way of doing code reuse.

01:00 Parts one and two are the how, whereas part three is the why. It concentrates on the design philosophy behind object-oriented coding and introduces SOLID, an acronym that provides guidance on writing well-structured object-oriented software.

01:17 This is part one, Class Concepts, and in it you will learn why you might want to write object-oriented code, how to write classes, what attributes and methods are, and how to use the descriptor protocol.

01:33 The code in this course was written with Python 3.11. Object-oriented coding in Python has gone through some changes over the years, and so the code presented here won’t work in Python 2 without some changes.

01:46 For the most part, I’ve stuck with general Python 3, but there is the odd line here or there that uses newer language features. I’ll point those out when they occur.

01:57 Python is a mixed bag and includes high-level concepts from a variety of different language styles. It has procedural coding (that’s the straightforward scripting-type stuff), functional coding (including patterns like lambdas, comprehensions, and map/reduce), and what this course is about: object-oriented coding. For all three of these, Python takes a sort of loose approach.

02:21 You can take or leave these features as makes sense for the code you’re writing. This is in contrast to languages like Java that are strictly object oriented, where even "Hello, World" requires object-oriented concepts.

02:35 If you’ve never come across the term before, object-oriented coding is an approach where you group data and operations on that data together in a structure. In Python, you use the class keyword to declare just such a structure.

02:48 The class is used to then create objects. A piece of data on an object is called an attribute, while the operations (like functions) are known as methods.

03:00 There are a variety of ways of declaring and using both attributes and methods, each with different purposes. This course will show you these differences and how to take advantage of them in your code.

03:11 Your first foray into the object-oriented world covers why you might want to foray into the object-oriented world. Foray is just a fun word to say.

Avatar image for Олег Камуз

Олег Камуз on Sept. 8, 2023

Where is B: Inheritance and Intrenals and C:Design and Guiedance section of this course ?

Avatar image for Christopher Trudeau

Christopher Trudeau RP Team on Sept. 9, 2023

Part 2 and 3 haven’t been released yet. They’re being processed and should be launched shortly.

Avatar image for nstraat

nstraat on Nov. 18, 2023

hi, by now they are available. maybe you could add the links to the contents pages of part 1 and 2.

course 2. realpython.com/courses/python-class-inheritance/

course 3. realpython.com/courses/solid-principles-python/

Become a Member to join the conversation.