From the course: Python Object-Oriented Programming
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Class methods and members - Python Tutorial
From the course: Python Object-Oriented Programming
Class methods and members
- [Instructor] Let's finish up this chapter by examining two more kinds of methods and attributes. We're going to take a look at class methods and static methods. So here in my editor, I'm going to open up class_start and there's already some code filled out for the Book class. We've already seen how the init function works and we've already learned about how instance functions work. And we know for example that the set_title function is an instance function that sets the book's title. And the title attribute is an instance attribute because its value is associated with each instance of the object that gets created. So let's start with class level methods and attributes. These are different from their instance versions because they are shared at the class level across all instances of that class. So that might sound a little confusing. So let's take a look at a concrete example. Suppose we wanted to make sure that each book…