From the course: Python Object-Oriented Programming
Unlock the full course today
Join today to access over 24,500 courses taught by industry experts.
Instance methods and attributes - Python Tutorial
From the course: Python Object-Oriented Programming
Instance methods and attributes
- [Instructor] In the previous video we saw how to define a basic Python class and create an instance of it. Now let's see how to create instance methods and attributes for our class. So in the editor, let's open up instance_start. And you can see here this is pretty much how we left the code in the previous example. So let's start by filling out the init method a little bit more, since books tend to have more information about them than just their title. So I'm going to add author, pages, and price. And then I'm going to add those properties down here. So self.author is going to equal the author argument and we'll do the same for pages and, of course, the price. So each one of these attributes is called an instance attribute because the value that it holds is only used by the instance of the object that it is declared on. And the same goes for instance methods. So far we only have one, which is the init method, and…