Learn practical skills, build real-world projects, and advance your career
Created 4 years ago
Classes and subclasses
In this notebook, I will show you the basics of classes and subclasses in Python. As you've seen in the lectures from this week, Trax
uses layer classes as building blocks for deep learning models, so it is important to understand how classes and subclasses behave in order to be able to build custom layers when needed.
By completing this notebook, you will:
- Be able to define classes and subclasses in Python
- Understand how inheritance works in subclasses
- Be able to work with instances
Part 1: Parameters, methods and instances
First, let's define a class My_Class
.
class My_Class: #Definition of My_class
x = None
My_Class
has one parameter x
without any value. You can think of parameters as the variables that every object assigned to a class will have. So, at this point, any object of class My_Class
would have a variable x
equal to None
. To check this, I'll create two instances of that class and get the value of x
for both of them.