Save this video free

Python (Fall 2026) Module 14-3: Class Methods

Bill Moseley, Ph.D. - Computer Science Educator · 12:11 · Watch on YouTube

Part of Bakersfield College COMP B10. See all 36 lectures and search them

These notes were made with YouTube Collector. Paste any YouTube link and get the same: a summary, chapters and a searchable transcript.

Overview

Bill Moseley demonstrates how a Python class method uses `self` to update state belonging to a particular object: `driveCar(intDistance)` adds miles to that car's `intMiles` property. Two calls driving 100 and 38 miles show the odometer accumulating to 138, while separate `clCar` instances maintain independent mileage; Moseley also explains that `pickle` can preserve object data between program runs.

Key takeaways

Chapters

0:00 How `self` Connects `driveCar` to a Car's Mileage
2:18 Implementing and Testing `clCar.driveCar`
8:19 Separate Mileage for Each `clCar` Object

Keep these chapters and the full searchable transcript in your own library.

Transcript excerpt

0:01 Classes also define methods. And just going  with our car example here, here's another car class. And it's got an integer property called  miles. intMiles, and it, it starts out with 100 miles. It also has, you can see now, inside. So  this method, or this function that I'm creating, is a method because it's part of a class. So  when I say int, or when I say clCar.driveCar, I'm going to give it two arguments. Every method  has self in it. And the, what that means is, when we pass self to a method, what it does is  it allows us to refer to that instance so that

1:02 we can access the properties of that instance.  The other parameter here is intHowFar. So it's, how far do I want to drive? So I'm going to  tell it to drive a certain distance. And this is passed invisibly. So that's just going to be  there. But you have to put it when you define the function. But you can see down here, I don't  have to give that when I call the function or call that method. So inside this method,  I've got self.intMiles, and I'm adding that argument. So whatever I put in there and goes  to that property gets added to the intMiles, self.intMiles. So it will increase that by however  much I put here, and then it, all it does is just

1:55 print some stuff. So I, if I create a instance of  that car and then I drive that car 50 miles, the the property intMiles will be increased by 50. So let's come back to this.  I'm going to delete this, and I'm just going to add to this, to this  class, and I'm going say intMiles, and I'll start out at zero. And now I'm going to create  that driveCar method. So let's say def driveCar.

This is the start of the transcript. Save this video free for the whole transcript, searchable and time-coded.

In this course

Related notes

Summary, takeaways, and chapters were generated by AI from the video's transcript and may contain errors. The video belongs to its creator, Bill Moseley, Ph.D. - Computer Science Educator.

Want the full transcript?

Save this video in YouTube Collector to get its complete searchable transcript, your own AI summaries, and a library that keeps every video you collect in one place.