Learn about methods in Python.
We'll cover the following
Introduction to methods
Sometimes, we see certain object functions are called methods. We added a
bark() function to the
Dog class, and both the
mutley objects made from this class have a
bark() method. We saw them both bark in the example.
Neural networks take some input, do some calculations, and produce an output. We also know they can be trained. We can see that these actions, training and producing an answer, are natural functions of a neural network. That is, they are a function of a neural network object. We also need to remember that neural networks have data inside them that naturally belongs there—the link weights. That’s why we’ll build our neural network as an object.
For a complete overview, let’s see how we add data variables to a class, and look at some methods to view and change this data. Let’s have a look at the fresh class definition of a
Dog class below. There’s a few new things going on here, so we’ll look at them one at a time.