Classes and Inheritance
In this lesson, you'll learn about the concepts of classes and inheritance in Python.
We'll cover the following
Class definition
A class describes a new type of object and bundles together the methods needed to work with objects of that type. Here is an analogy: a class is like a cake recipe, while objects are the cakes you can make by following the recipe.
Defining a class
The syntax for defining a class is
class ClassName(superclass):
variable and method definitions
Introduction to inheritance
Every class (except the object
class) has a
For example, you might define a class Person
with the variables name
and age
and a method greet
. Every object of this type will have its own copies of those variables, and its own reference to the greet
method. If you then create a class Customer
as a subclass of Person
, every object of type Customer
will have its own name
and age
variables and a greet
method. Plus, it will have whatever additional variables and methods you declare in Customer
(for example, a list of purchases).
Create a free account to view this lesson.
By signing up, you agree to Educative's Terms of Service and Privacy Policy