From the course: Python Object-Oriented Programming

Unlock the full course today

Join today to access over 24,500 courses taught by industry experts.

Basic class definition

Basic class definition

- [Instructor] Let's begin by seeing how to create a basic class definition in Python, along with how to instantiate the class and then access parts of it. So here in chapter one in the start folder I'm going to open up the definition_start code and we're going to start by creating a class to represent a book. So to do that, I'm going to use the class keyword. So I type the word class and then the name of the class. And in this case I'll type the word book and then a colon. You can also optionally add parentheses after the class name, but they're only really required if you're going to indicate that the class inherits from another class. And we'll get to that later in the course. Since our class just exists on its own we can just leave those off. Now, to complete the class definition I can just add a pass statement which doesn't do anything and be done. This is a perfectly legal syntactically correct class definition in…

Contents