-
Introduction 4
-
Lecture1.1
-
Lecture1.2
-
Lecture1.3
-
Lecture1.4
-
-
Production Possibilities Frontier 4
-
Lecture2.1
-
Lecture2.2
-
Lecture2.3
-
Lecture2.4
-
-
Trade 3
-
Lecture3.1
-
Lecture3.2
-
Lecture3.3
-
-
Demand 4
-
Lecture4.1
-
Lecture4.2
-
Lecture4.3
-
Lecture4.4
-
-
Supply 2
-
Lecture5.1
-
Lecture5.2
-
-
Equilibrium 4
-
Lecture6.1
-
Lecture6.2
-
Lecture6.3
-
Lecture6.4
-
-
Curve Movements 4
-
Lecture7.1
-
Lecture7.2
-
Lecture7.3
-
Lecture7.4
-
-
Elasticity and Revenue 5
-
Lecture8.1
-
Lecture8.2
-
Lecture8.3
-
Lecture8.4
-
Lecture8.5
-
-
Taxes 7
-
Lecture9.1
-
Lecture9.2
-
Lecture9.3
-
Lecture9.4
-
Lecture9.5
-
Lecture9.6
-
Lecture9.7
-
-
Consumer and Producer Surplus 8
-
Lecture10.1
-
Lecture10.2
-
Lecture10.3
-
Lecture10.4
-
Lecture10.5
-
Lecture10.6
-
Lecture10.7
-
Lecture10.8
-
-
Imports and Exports 4
-
Lecture11.1
-
Lecture11.2
-
Lecture11.3
-
Lecture11.4
-
-
Tariffs 2
-
Lecture12.1
-
Lecture12.2
-
Creating a Class
Until now, I have not used any classes in our lessons. Classes are ways to create replicable objects. For example, maybe we are doing an analysis using cars, and what a basic framework of how we represent it in code. From this class you can then plug in initial conditions, and change parts of it through codes. We will work through an example of a car to learn how classes work.
Let’s start out with the below class.
class car:
def __init__(self,brandName):
self.brand = brandName
The first line creates a class with the word class followed by the name of the class, in our case it is car. Just like functions, we use indenting to signify what is in, and out of the class. The second line initializes our class, what this means is it handles creation of the class in the beginning. It gets called once in the beginning. You always need to specify self for the first argument, and then after you give it any other arguments you want. In this case we want to get the brand name for the car. The third line assigns the variable in the init function to our class. Classes have attributes, which are variables attached to them. You access these variables by doing self.variable where variable is the name of your variable. This line takes the variable and assigns it to the brand variable of our class.
Let’s create a new car, which we will call ourCar, and give it the brand ford.
ourCar = car("Ford")
When you print out the object, you don’t get anything interesting out of it.
print(ourCar)
If we wanted to see the brand though, we would be able to print out the brand attribute.
print(ourCar.brand)
Challenge