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.51
List Price:  €69.04
You save:  €34.52
£30.03
List Price:  £60.08
You save:  £30.04
CA$56.07
List Price:  CA$112.15
You save:  CA$56.08
A$61.64
List Price:  A$123.30
You save:  A$61.66
S$51.95
List Price:  S$103.92
You save:  S$51.96
HK$310.72
List Price:  HK$621.52
You save:  HK$310.80
CHF 31.86
List Price:  CHF 63.74
You save:  CHF 31.87
NOK kr401.91
List Price:  NOK kr803.93
You save:  NOK kr402.01
DKK kr257.81
List Price:  DKK kr515.68
You save:  DKK kr257.87
NZ$69.66
List Price:  NZ$139.35
You save:  NZ$69.68
د.إ146.86
List Price:  د.إ293.76
You save:  د.إ146.90
৳4,885.14
List Price:  ৳9,771.51
You save:  ৳4,886.36
₹3,508.98
List Price:  ₹7,018.84
You save:  ₹3,509.86
RM169.15
List Price:  RM338.35
You save:  RM169.20
₦58,662.13
List Price:  ₦117,338.93
You save:  ₦58,676.80
₨11,327.80
List Price:  ₨22,658.43
You save:  ₨11,330.63
฿1,315.63
List Price:  ฿2,631.59
You save:  ฿1,315.96
₺1,678.63
List Price:  ₺3,357.69
You save:  ₺1,679.05
B$215.47
List Price:  B$430.99
You save:  B$215.52
R698.96
List Price:  R1,398.11
You save:  R699.14
Лв67.44
List Price:  Лв134.89
You save:  Лв67.45
₩57,256.54
List Price:  ₩114,527.40
You save:  ₩57,270.86
₪131.86
List Price:  ₪263.76
You save:  ₪131.89
₱2,337.73
List Price:  ₱4,676.05
You save:  ₱2,338.31
¥6,071.28
List Price:  ¥12,144.08
You save:  ¥6,072.80
MX$735.85
List Price:  MX$1,471.89
You save:  MX$736.04
QR145.92
List Price:  QR291.87
You save:  QR145.95
P534.01
List Price:  P1,068.15
You save:  P534.14
KSh5,164.70
List Price:  KSh10,330.70
You save:  KSh5,166
E£1,901.52
List Price:  E£3,803.52
You save:  E£1,902
ብር6,038.47
List Price:  ብር12,078.45
You save:  ብር6,039.98
Kz36,470
List Price:  Kz72,949.12
You save:  Kz36,479.12
CLP$37,975.70
List Price:  CLP$75,960.90
You save:  CLP$37,985.20
CN¥284.92
List Price:  CN¥569.92
You save:  CN¥285
RD$2,547.56
List Price:  RD$5,095.76
You save:  RD$2,548.20
DA5,206.89
List Price:  DA10,415.09
You save:  DA5,208.20
FJ$91.93
List Price:  FJ$183.88
You save:  FJ$91.95
Q306.63
List Price:  Q613.34
You save:  Q306.71
GY$8,375.76
List Price:  GY$16,753.62
You save:  GY$8,377.85
ISK kr4,894.77
List Price:  ISK kr9,790.77
You save:  ISK kr4,896
DH368.81
List Price:  DH737.71
You save:  DH368.90
L679.76
List Price:  L1,359.69
You save:  L679.93
ден2,126.49
List Price:  ден4,253.52
You save:  ден2,127.02
MOP$320.46
List Price:  MOP$641
You save:  MOP$320.54
N$693.29
List Price:  N$1,386.76
You save:  N$693.46
C$1,473.12
List Price:  C$2,946.62
You save:  C$1,473.49
रु5,632.10
List Price:  रु11,265.62
You save:  रु5,633.51
S/135.05
List Price:  S/270.14
You save:  S/135.08
K170.84
List Price:  K341.73
You save:  K170.89
SAR149.97
List Price:  SAR299.99
You save:  SAR150.01
ZK905.77
List Price:  ZK1,811.78
You save:  ZK906
L175.43
List Price:  L350.90
You save:  L175.47
Kč839.13
List Price:  Kč1,678.47
You save:  Kč839.34
Ft13,432.80
List Price:  Ft26,868.96
You save:  Ft13,436.16
SEK kr377.49
List Price:  SEK kr755.09
You save:  SEK kr377.59
ARS$58,276.64
List Price:  ARS$116,567.85
You save:  ARS$58,291.21
Bs276.63
List Price:  Bs553.33
You save:  Bs276.69
COP$155,770.71
List Price:  COP$311,580.38
You save:  COP$155,809.66
₡20,093.12
List Price:  ₡40,191.28
You save:  ₡20,098.15
L1,051.86
List Price:  L2,103.99
You save:  L1,052.12
₲283,589.36
List Price:  ₲567,249.64
You save:  ₲283,660.27
$U1,592.21
List Price:  $U3,184.83
You save:  $U1,592.61
zł146.09
List Price:  zł292.22
You save:  zł146.12
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.