Assignment Operators

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
$39.99
List Price:  $79.99
You save:  $40
€34.36
List Price:  €68.73
You save:  €34.37
£29.84
List Price:  £59.69
You save:  £29.85
CA$55.08
List Price:  CA$110.18
You save:  CA$55.10
A$61.41
List Price:  A$122.85
You save:  A$61.43
S$51.52
List Price:  S$103.05
You save:  S$51.53
HK$312.13
List Price:  HK$624.35
You save:  HK$312.21
CHF 32.19
List Price:  CHF 64.39
You save:  CHF 32.20
NOK kr400.12
List Price:  NOK kr800.35
You save:  NOK kr400.22
DKK kr256.45
List Price:  DKK kr512.97
You save:  DKK kr256.51
NZ$68.27
List Price:  NZ$136.57
You save:  NZ$68.29
د.إ146.86
List Price:  د.إ293.76
You save:  د.إ146.90
৳4,869.27
List Price:  ৳9,739.76
You save:  ৳4,870.49
₹3,524.71
List Price:  ₹7,050.30
You save:  ₹3,525.59
RM169.27
List Price:  RM338.59
You save:  RM169.32
₦61,275.07
List Price:  ₦122,565.47
You save:  ₦61,290.40
₨11,351.57
List Price:  ₨22,705.99
You save:  ₨11,354.41
฿1,295.43
List Price:  ฿2,591.19
You save:  ฿1,295.76
₺1,645.70
List Price:  ₺3,291.82
You save:  ₺1,646.11
B$217.74
List Price:  B$435.55
You save:  B$217.80
R708.73
List Price:  R1,417.64
You save:  R708.90
Лв67
List Price:  Лв134.02
You save:  Лв67.01
₩55,770.52
List Price:  ₩111,554.98
You save:  ₩55,784.46
₪135.60
List Price:  ₪271.25
You save:  ₪135.64
₱2,298.32
List Price:  ₱4,597.22
You save:  ₱2,298.90
¥5,941.06
List Price:  ¥11,883.61
You save:  ¥5,942.55
MX$750.26
List Price:  MX$1,500.70
You save:  MX$750.44
QR146.03
List Price:  QR292.09
You save:  QR146.06
P574.53
List Price:  P1,149.20
You save:  P574.67
KSh5,166.70
List Price:  KSh10,334.70
You save:  KSh5,168
E£1,939.49
List Price:  E£3,879.47
You save:  E£1,939.98
ብር5,681.79
List Price:  ብር11,365.01
You save:  ብር5,683.21
Kz36,469.08
List Price:  Kz72,947.28
You save:  Kz36,478.20
CLP$38,717.51
List Price:  CLP$77,444.71
You save:  CLP$38,727.20
CN¥285.16
List Price:  CN¥570.39
You save:  CN¥285.23
RD$2,516.45
List Price:  RD$5,033.54
You save:  RD$2,517.08
DA5,193.10
List Price:  DA10,387.51
You save:  DA5,194.40
FJ$90.45
List Price:  FJ$180.93
You save:  FJ$90.48
Q306.92
List Price:  Q613.92
You save:  Q307
GY$8,374.04
List Price:  GY$16,750.18
You save:  GY$8,376.14
ISK kr4,933.96
List Price:  ISK kr9,869.16
You save:  ISK kr4,935.20
DH359.99
List Price:  DH720.08
You save:  DH360.08
L664.67
List Price:  L1,329.51
You save:  L664.84
ден2,102.60
List Price:  ден4,205.72
You save:  ден2,103.12
MOP$321.59
List Price:  MOP$643.27
You save:  MOP$321.67
N$703.83
List Price:  N$1,407.84
You save:  N$704.01
C$1,473.65
List Price:  C$2,947.67
You save:  C$1,474.01
रु5,648.69
List Price:  रु11,298.79
You save:  रु5,650.10
S/141.43
List Price:  S/282.89
You save:  S/141.46
K169.54
List Price:  K339.12
You save:  K169.58
SAR150.05
List Price:  SAR300.14
You save:  SAR150.09
ZK946.07
List Price:  ZK1,892.38
You save:  ZK946.31
L174.54
List Price:  L349.12
You save:  L174.58
Kč841.12
List Price:  Kč1,682.46
You save:  Kč841.33
Ft13,613.08
List Price:  Ft27,229.58
You save:  Ft13,616.49
SEK kr378.09
List Price:  SEK kr756.29
You save:  SEK kr378.19
ARS$55,055.52
List Price:  ARS$110,124.81
You save:  ARS$55,069.29
Bs276.68
List Price:  Bs553.44
You save:  Bs276.75
COP$161,780.26
List Price:  COP$323,600.99
You save:  COP$161,820.72
₡20,244.43
List Price:  ₡40,493.93
You save:  ₡20,249.49
L1,048.40
List Price:  L2,097.07
You save:  L1,048.66
₲289,232.23
List Price:  ₲578,536.79
You save:  ₲289,304.56
$U1,600.17
List Price:  $U3,200.74
You save:  $U1,600.57
zł146.62
List Price:  zł293.27
You save:  zł146.65
Already have an account? Log In

Transcript

Today we are going to talk about the assignment operators. Previously, we talked about the increase and decrease of a number by one. So for example, here we have a variable called W. And if I want to increase it by one, I would just type plus plus, and semicolon. And I printed and I run our program, and as you can see, it has been increased by one. And if I want to decrease it, I would do the same. But what if I want to increase it by more than one?

Let's say we want to increase it by five. What do they do? Well, we cannot just do something like a plus plus and then five, and then semicolon. This is not how it works. If I want to increase W by five, what I would do is I would type w equals w plus five. That means that w here is the old value which equals to five, which equals to 10 plus five, and w is the new value which which equals to the old value plus five.

So now if I save and run, as you can see, I have 15. And if I want to win way to shortcut this operation, what I would do is I would type w plus equals five. And let me delete this one for now I'm going to comment this out. And if I save and run, as you can see, now it equals 15, which means that this line of code is equivalent to this line of code, which is w equals w plus five. And if I want to decrease it by five, I would do the same exactly the same. Instead of writing w equals w minus five, what are you would do is I would just type w minus equals five, and then I should print the value out.

And as you can see, now, it has been decreased by five. So this is this line of code is equivalent to this line of code. And if you want to multiply by five, or even divide by five, or whatever, you just change the operation, this operation by the operations that you want you want to do. So for example, if I want to multiply W by five, what I would do is I would type w multiply which is v star, the star sign and then equals five which is equivalent to w equals w. And then star five and I'm going to show you both both of these lines. So if I run this for the Firstly, if I run This, I would get 50 because five multiply by 10, the value is 50. But if I use the other equivalent syntax, I would type W star equals five.

If I run now the value is 50 again, so I can do that with division, multiplication and subtraction. So what I want you to do is to practice using this syntax, which is the operation and then equals, and then the number that you want to add or divide or subtract from the old value.

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.