Simple Example

3 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$99.99
List Price:  $139.99
You save:  $40
€86.29
List Price:  €120.81
You save:  €34.51
£74.96
List Price:  £104.94
You save:  £29.98
CA$137.30
List Price:  CA$192.22
You save:  CA$54.92
A$141.97
List Price:  A$198.76
You save:  A$56.79
S$128.23
List Price:  S$179.53
You save:  S$51.30
HK$783.44
List Price:  HK$1,096.85
You save:  HK$313.41
CHF 78.83
List Price:  CHF 110.37
You save:  CHF 31.53
NOK kr956.26
List Price:  NOK kr1,338.80
You save:  NOK kr382.54
DKK kr645.68
List Price:  DKK kr903.98
You save:  DKK kr258.30
NZ$171.24
List Price:  NZ$239.75
You save:  NZ$68.50
د.إ367.21
List Price:  د.إ514.11
You save:  د.إ146.90
৳12,248.26
List Price:  ৳17,148.06
You save:  ৳4,899.79
₹9,400.11
List Price:  ₹13,160.53
You save:  ₹3,760.42
RM393.91
List Price:  RM551.49
You save:  RM157.58
₦135,249.22
List Price:  ₦189,354.32
You save:  ₦54,105.09
₨27,869.34
List Price:  ₨39,018.20
You save:  ₨11,148.85
฿3,260.08
List Price:  ฿4,564.24
You save:  ฿1,304.16
₺4,424.80
List Price:  ₺6,194.90
You save:  ₺1,770.10
B$531.28
List Price:  B$743.82
You save:  B$212.53
R1,712.57
List Price:  R2,397.67
You save:  R685.09
Лв169
List Price:  Лв236.61
You save:  Лв67.60
₩150,515.94
List Price:  ₩210,728.34
You save:  ₩60,212.40
₪310.86
List Price:  ₪435.22
You save:  ₪124.35
₱6,014.39
List Price:  ₱8,420.39
You save:  ₱2,406
¥15,921.91
List Price:  ¥22,291.31
You save:  ¥6,369.40
MX$1,789.64
List Price:  MX$2,505.56
You save:  MX$715.92
QR365.01
List Price:  QR511.03
You save:  QR146.02
P1,361.11
List Price:  P1,905.62
You save:  P544.50
KSh12,931.45
List Price:  KSh18,104.56
You save:  KSh5,173.10
E£5,175.34
List Price:  E£7,245.68
You save:  E£2,070.34
ብር15,731.51
List Price:  ብር22,024.74
You save:  ብር6,293.23
Kz91,690.83
List Price:  Kz128,370.83
You save:  Kz36,680
CLP$91,353.50
List Price:  CLP$127,898.55
You save:  CLP$36,545.05
CN¥688.57
List Price:  CN¥964.02
You save:  CN¥275.45
RD$5,925.30
List Price:  RD$8,295.65
You save:  RD$2,370.35
DA13,223.47
List Price:  DA18,513.39
You save:  DA5,289.92
FJ$221.42
List Price:  FJ$310
You save:  FJ$88.57
Q764.62
List Price:  Q1,070.50
You save:  Q305.87
GY$20,883.90
List Price:  GY$29,238.30
You save:  GY$8,354.39
ISK kr12,404.40
List Price:  ISK kr17,366.66
You save:  ISK kr4,962.25
DH932.75
List Price:  DH1,305.89
You save:  DH373.13
L1,730.83
List Price:  L2,423.24
You save:  L692.40
ден5,316.72
List Price:  ден7,443.63
You save:  ден2,126.90
MOP$805.72
List Price:  MOP$1,128.04
You save:  MOP$322.32
N$1,683.88
List Price:  N$2,357.50
You save:  N$673.62
C$3,673.01
List Price:  C$5,142.36
You save:  C$1,469.35
रु14,941.86
List Price:  रु20,919.21
You save:  रु5,977.34
S/345.10
List Price:  S/483.16
You save:  S/138.05
K430.87
List Price:  K603.24
You save:  K172.36
SAR375.42
List Price:  SAR525.61
You save:  SAR150.18
ZK1,948.99
List Price:  ZK2,728.66
You save:  ZK779.67
L440.10
List Price:  L616.16
You save:  L176.06
Kč2,114.70
List Price:  Kč2,960.67
You save:  Kč845.96
Ft34,137.93
List Price:  Ft47,794.47
You save:  Ft13,656.53
SEK kr934.30
List Price:  SEK kr1,308.06
You save:  SEK kr373.76
ARS$137,853.56
List Price:  ARS$193,000.49
You save:  ARS$55,146.93
Bs689.74
List Price:  Bs965.67
You save:  Bs275.92
COP$366,904.60
List Price:  COP$513,681.11
You save:  COP$146,776.51
₡46,624.36
List Price:  ₡65,275.97
You save:  ₡18,651.61
L2,642.10
List Price:  L3,699.04
You save:  L1,056.94
₲651,970.09
List Price:  ₲912,784.21
You save:  ₲260,814.11
$U4,022.37
List Price:  $U5,631.48
You save:  $U1,609.11
zł369.03
List Price:  zł516.66
You save:  zł147.62
Already have an account? Log In

Transcript

Hello in this video we are going to look at a simple class example. What is a class classes are amazing classes allow you to encapsulate code and think of it like this. You have vehicles all over the world he left a game from them you have vehicles and you have a car that's a vehicle you have a motorbike that's a vehicle you have like a train that's a vehicle and the car has a speed, a motorbike, whatever speed, a train with the speed, counterweight, a motorbike, whatever weight, a train whatever weight, you see where I'm going here, they have similar properties. And they might have similar methods. One method might be accelerate, one more method might be D federate, no very similar sort of methods. And what we can do is create a class called vehicle for example.

And you'll have the properties I'm just create instances of the class and they each instance has its own unique set of values, but he shares common functionality, quality To take in. And if you don't get the first time go over the videos again, because honestly, it's the actual idea. The philosophy around classes is called object oriented programming. And it is one of the outside pitfalls that a lot of new developers fall into. So if you haven't come across object oriented programming, and you get a bit confused, don't worry, that is just natural. So in this video, simple example, the next video, we're going to look at creating instances of our class.

So to create a class, we simply have to use the keyword class. And then you specify the class name. So I want to say, a vehicle nastic vehicle class, in the, the example I always use when I'm teaching university as well. So now you can specify like any variables, so these will be global variables. So for this variable, I'm going to put speed for example, I'll set a default value of zero so by default, you know not not good. They can define as many methods as you want, I can put multiple variable as well, I'm gonna put one.

So we've already done methods, but the process is similar. So if I just say, play, I'm gonna say, increase speed, and I'm gonna pass in a parameter of increase amount. And something else to note is all methods in Python have to have DSL self keyword at the start, you won't actually pass anything in for the self keyword, this automatically passes in the instance of the class itself. So you will just pass in increase amount or those free variables including self data, passing the two variables, not the self. Okay, so put a colon in here. We are just going to say Got speed.

So this accessing the speed of this self. And we're going to say plus equals to increase amount. So we just add it to, we just add increase amount to speed. I think this is a very simple example. That's all there is to it. You can add more functions, you can add more variable that you can have a few other extra features that we'll cover throughout this series for that this is a very simple example.

In the next video, we're going to look at actually creating an instance of our class. And let's just run this just to make sure we're not getting any errors. Obviously, you won't display anything. We haven't done any prints. Last one. Thanks for watching, and I look forward to seeing you in the next Python class video.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.