1
00:00:05,360 --> 00:00:08,189
So in the previous video we drew
attention to the fact that there's code

2
00:00:08,189 --> 00:00:12,340
warnings in IntelliJ, and they're those
dashes you saw on the right hand side.

3
00:00:12,340 --> 00:00:15,250
So, right at the moment now we
haven't typed anything in, but

4
00:00:15,250 --> 00:00:18,700
you'll notice the little green arrow
there, which is actually indicating that

5
00:00:18,700 --> 00:00:21,030
there's no actual errors in the code or
no warnings.

6
00:00:21,030 --> 00:00:24,790
So as I start typing, i'm gonna actually
type in the program that we actually typed

7
00:00:24,790 --> 00:00:26,010
in in the last section.

8
00:00:26,010 --> 00:00:31,550
Notice the little warnings
that actually come

9
00:00:31,550 --> 00:00:34,890
up, the little lines as I type.

10
00:00:34,890 --> 00:00:36,280
So I type number=9223372036854775807.

11
00:00:36,280 --> 00:00:38,270
So far, so good.

12
00:00:38,270 --> 00:00:44,230
You'll notice there's a little I
there showing as I was typing and

13
00:00:44,230 --> 00:00:45,470
that it actually ended up with a t.

14
00:00:45,470 --> 00:00:49,500
So as I'm typing,
it's actually scanning and

15
00:00:49,500 --> 00:00:51,190
giving us errors if
there are errors there.

16
00:00:51,190 --> 00:00:55,300
So cleaned number, equals double quote,

17
00:00:55,300 --> 00:01:00,320
double quote gives us two quotes, and
I'll add a few more spaces there so

18
00:01:00,320 --> 00:01:02,740
we can be clear about what
we're trying to do here.

19
00:01:02,740 --> 00:01:06,710
So, for i in range, just going to
type this program in again now,

20
00:01:06,710 --> 00:01:10,060
0, len(number), again,
this is the old version.

21
00:01:10,060 --> 00:01:15,940
If number

22
00:01:15,940 --> 00:01:20,950
I in 0123456789, then we're gonna do

23
00:01:20,950 --> 00:01:27,440
cleanedNumber = cleanedNumber,
plus number I.

24
00:01:27,440 --> 00:01:31,240
And it's just a couple more lines.

25
00:01:31,240 --> 00:01:33,830
New number, whoops,
getting our indentation numbers correct.

26
00:01:33,830 --> 00:01:37,200
New number equals int,

27
00:01:37,200 --> 00:01:41,980
clean number,
then print into the top of there.

28
00:01:43,230 --> 00:01:46,800
Come back to the minute print,
the number is

29
00:01:49,800 --> 00:01:53,610
.format(newNumber) and fix that typo.

30
00:01:53,610 --> 00:01:56,560
And again notice that when you
have actually made a typo,

31
00:01:56,560 --> 00:01:59,880
it does actually appear as
here as some warning as well.

32
00:01:59,880 --> 00:02:00,720
So type int.

33
00:02:02,040 --> 00:02:02,910
Fix that up.

34
00:02:02,910 --> 00:02:06,900
So if you actually type it in, exactly as
I've typed it in here, the first real code

35
00:02:06,900 --> 00:02:10,990
of course starts on line three, the number
we're actually assigning the value

36
00:02:10,990 --> 00:02:14,620
into a number variable, you should see
a marker at the end of line eight.

37
00:02:14,620 --> 00:02:15,290
So coming down here,

38
00:02:15,290 --> 00:02:19,330
there's actually one on line three as
well, missing white space around operator.

39
00:02:19,330 --> 00:02:23,130
So what I should have done there is put,
= and a space, like so.

40
00:02:23,130 --> 00:02:24,600
And that will get rid off that one.

41
00:02:24,600 --> 00:02:25,940
But the one we wanna look at first,

42
00:02:25,940 --> 00:02:28,840
before we get started,
is this one here on line eight.

43
00:02:28,840 --> 00:02:30,750
So if you hover over
this with a mouse again,

44
00:02:30,750 --> 00:02:33,570
it says, assignments can be
replaced with augmented assignment.

45
00:02:33,570 --> 00:02:36,240
And again, with these warnings we're
already on that line, but if you click on

46
00:02:36,240 --> 00:02:38,860
them you will actually go for that
line and sort of parse button as well.

47
00:02:38,860 --> 00:02:41,200
You can start editing it as well.

48
00:02:41,200 --> 00:02:43,400
So in this case,
this is actually not an error.

49
00:02:43,400 --> 00:02:47,020
It's more of a suggestion, but given that
in the last videos I recommended you

50
00:02:47,020 --> 00:02:48,390
checking out these markers,

51
00:02:48,390 --> 00:02:51,530
this is actually a good place to
discuss the augmented assignment.

52
00:02:51,530 --> 00:02:54,020
Which of course is not what
it's actually asking about,

53
00:02:54,020 --> 00:02:57,580
it's actually mentioning that maybe we
should be using augmented assignment.

54
00:02:57,580 --> 00:03:00,450
So I know augmented assignment
sounds really fancy, but

55
00:03:00,450 --> 00:03:03,350
it's really just a short-hand way
of assigning values to a variable.

56
00:03:03,350 --> 00:03:08,510
Now the Python documentation describes
them as the following, the combination in

57
00:03:08,510 --> 00:03:13,930
single statement of a binary operation and
an assignment statement, which is true but

58
00:03:13,930 --> 00:03:18,620
If you're like me, listening to that
doesn't sound terribly understandable.

59
00:03:18,620 --> 00:03:21,730
So in line eight we performed
the concatenation of clean number plus

60
00:03:21,730 --> 00:03:22,860
number i.

61
00:03:22,860 --> 00:03:25,100
Then we assigned the result
to clean number.

62
00:03:25,100 --> 00:03:27,900
So the concatenation is
the binary operation.

63
00:03:27,900 --> 00:03:30,200
Binary because it takes
two upper ends to work on.

64
00:03:30,200 --> 00:03:32,620
And then of course,
there's the assignment after that.

65
00:03:32,620 --> 00:03:35,850
So what you could do to change this to
an augmented assignment, we could instead,

66
00:03:35,850 --> 00:03:38,090
I have this example I've
done here on line eight.

67
00:03:38,090 --> 00:03:42,650
We could have actually done this,
+=number i.

68
00:03:42,650 --> 00:03:47,840
When we do that, the warning indicator
over here has now disappeared,

69
00:03:47,840 --> 00:03:50,500
and it's telling that this
is a more efficient way.

70
00:03:50,500 --> 00:03:52,880
It's a short hand way for
what we had in the past.

71
00:03:52,880 --> 00:03:56,490
Now if you're used to programming in Java
or C++, and particularly if you used

72
00:03:56,490 --> 00:04:01,130
IntelliJ ,then you would find that
IntelliJ doesn't make this suggestion for

73
00:04:01,130 --> 00:04:03,710
those languages,
because both statements are identical.

74
00:04:03,710 --> 00:04:05,310
The use is just really
a matter of preference.

75
00:04:05,310 --> 00:04:09,270
So whether you typed it in the long way or
the short way with the plus equal,

76
00:04:09,270 --> 00:04:12,800
as far as Java or C++,
which is two examples of languages.

77
00:04:12,800 --> 00:04:14,200
It makes no difference.

78
00:04:14,200 --> 00:04:18,390
Thing to keep in mind though, is that in
Python the augmented assignment form only

79
00:04:18,390 --> 00:04:23,800
evaluates the signee, which is
the clean number in this example, once.

80
00:04:23,800 --> 00:04:26,020
So, in the other form,
where clean number appeared twice,

81
00:04:26,020 --> 00:04:28,520
the variable is evaluated more than once.

82
00:04:28,520 --> 00:04:30,560
So, basically there's more work for
the computer to do.

83
00:04:30,560 --> 00:04:33,570
So, it's actually processing
that more than once.

84
00:04:33,570 --> 00:04:34,850
And also with the first form,

85
00:04:34,850 --> 00:04:38,830
plus the long winded way with clean
number equals clean number plus one.

86
00:04:38,830 --> 00:04:43,750
Python actually creates a new variable
in memory, assigns the value after

87
00:04:43,750 --> 00:04:47,580
performing the calculation,
then destroys the original version.

88
00:04:47,580 --> 00:04:50,780
Now using an augmented assignment
can perform the operation in place,

89
00:04:50,780 --> 00:04:52,740
with possible modifying of
the original variables.

90
00:04:52,740 --> 00:04:53,980
So there's less work.

91
00:04:53,980 --> 00:04:55,270
There's one less variable.

92
00:04:55,270 --> 00:04:59,760
In this case it would be created
internally from Python's perspective, and

93
00:04:59,760 --> 00:05:02,010
it's going to be more
efficient in most cases.

94
00:05:02,010 --> 00:05:05,360
With that said, it's not always possible,
depending on the type of object.

95
00:05:05,360 --> 00:05:07,800
We have the variable, in other words,
in question to the do this.

96
00:05:07,800 --> 00:05:09,710
But it can be done in
place wherever possible.

97
00:05:09,710 --> 00:05:13,150
And that's why in this case IntelliJ,
when you're using Python with IntelliJ,

98
00:05:13,150 --> 00:05:16,840
it's suggesting that you use augmented
assignments rather than longhand.

99
00:05:16,840 --> 00:05:20,960
Because unlike Java and other programming
languages, the shorthand way with the plus

100
00:05:20,960 --> 00:05:24,510
equals in this particular case
is actually a lot more efficient

101
00:05:24,510 --> 00:05:27,860
from Python's perspective, and
you'll ultimately, as you start writing

102
00:05:27,860 --> 00:05:30,940
real Python programs you're going to be
finding this is more efficient, and you're

103
00:05:30,940 --> 00:05:33,910
going to be actually saving resources
which is actually very important.

104
00:05:33,910 --> 00:05:35,730
And just a reminder that
this last line here,

105
00:05:35,730 --> 00:05:39,520
this last warning, it's saying there's
no new line at the end of file.

106
00:05:39,520 --> 00:05:43,450
We fix that by just creating an empty line
and that will actually remove that error.

107
00:05:43,450 --> 00:05:45,710
And we should in due course get
a little tick that'll appear up here.

108
00:05:45,710 --> 00:05:48,470
And again as I mentioned
the term augmented

109
00:05:48,470 --> 00:05:51,390
assignment sounds a lot more complicated,
and it really is.

110
00:05:51,390 --> 00:05:54,220
Sounds like it's a fancy term.

111
00:05:54,220 --> 00:05:55,810
It's really just a short
hand way as you saw.

112
00:05:55,810 --> 00:05:56,460
So the symbol for

113
00:05:56,460 --> 00:05:59,870
them is just like typing the binary
operator followed by an equal sign.

114
00:05:59,870 --> 00:06:01,920
So you could do something similar.

115
00:06:01,920 --> 00:06:03,810
You put plus there, but
you can use other ones.

116
00:06:03,810 --> 00:06:07,830
You can use the minus, and that would
be the equivalent to clean number=clean

117
00:06:07,830 --> 00:06:11,490
number, type number i, which doesn't make
sense in the context of this string, but

118
00:06:11,490 --> 00:06:14,290
it might be if you're
actually adding numbers.

119
00:06:14,290 --> 00:06:15,400
You could also use multiplication.

120
00:06:15,400 --> 00:06:17,320
That would be star equals like that.

121
00:06:17,320 --> 00:06:21,490
And then you could use slash for
division slash equals.

122
00:06:21,490 --> 00:06:24,570
So let's actually go through
an example of a couple of these so

123
00:06:24,570 --> 00:06:25,640
they actually make sense.

124
00:06:25,640 --> 00:06:27,830
So we can start by saying
x equals twenty three,

125
00:06:29,410 --> 00:06:31,260
then we could put x plus equals one.

126
00:06:31,260 --> 00:06:34,450
So applying this to numbers
makes a lot more sense.

127
00:06:34,450 --> 00:06:37,370
We put x of course we should
get the value twenty four.

128
00:06:37,370 --> 00:06:42,430
So if we run that I see we got
the value 24, so no surprises there.

129
00:06:42,430 --> 00:06:45,360
Then if we actually put x -= 4 and

130
00:06:45,360 --> 00:06:49,910
print that out again that
should be 24 take four.

131
00:06:49,910 --> 00:06:51,340
We should get the answer 20.

132
00:06:51,340 --> 00:06:55,940
And there's a second answer there,
it's 20, which is correct.

133
00:06:55,940 --> 00:06:59,790
And continuing on from
that we can write x=x*=5,

134
00:06:59,790 --> 00:07:04,220
that's what it is,
it's the abbreviation for it.

135
00:07:04,220 --> 00:07:07,510
And that should be 20 times 5 and
that should give us 100 when we run it.

136
00:07:07,510 --> 00:07:12,690
Let's say we've got 100 there and
if we try division x/=4,

137
00:07:12,690 --> 00:07:17,510
so x equals x divided by 4,
in other words.

138
00:07:17,510 --> 00:07:20,270
That should give us an answer of 25.

139
00:07:20,270 --> 00:07:25,080
Bearing in mind it's a flighty answer
because we only used a single division.

140
00:07:25,080 --> 00:07:29,910
And from there we could have done
something like x star, star equals two.

141
00:07:29,910 --> 00:07:36,890
And print that out and we should
get the answer of 625.0 from that.

142
00:07:36,890 --> 00:07:39,610
And of course if you recall star,
star is to the power.

143
00:07:39,610 --> 00:07:43,290
So it's basically 25 to the power of 25,

144
00:07:43,290 --> 00:07:46,640
which was to the power of 2
I should say which was 625.

145
00:07:46,640 --> 00:07:51,860
And lastly from our
remainder process x like so.

146
00:07:51,860 --> 00:07:56,060
If you print x from there, so
we're looking for the remainder.

147
00:07:56,060 --> 00:07:59,780
I've divided what the current value of
x is by 60, if we actually run that.

148
00:07:59,780 --> 00:08:00,890
We get the answer of 25.

149
00:08:00,890 --> 00:08:05,060
And that's because 60
goes into 625 ten times,

150
00:08:05,060 --> 00:08:10,260
leaving a remainder of 25, and the number
25 is what the answer is to that.

151
00:08:10,260 --> 00:08:15,820
And just to finish off, we can actually
apply some of these, binary operators.

152
00:08:15,820 --> 00:08:19,120
There's also two binary operators
that can be performed on strings.

153
00:08:19,120 --> 00:08:22,480
Concatenation which we've seen, but
we'll do again and also repetition.

154
00:08:22,480 --> 00:08:27,130
So we could put greeting = "Good"

155
00:08:27,130 --> 00:08:34,520
(greeting)+= "morning" print (greeting).

156
00:08:34,520 --> 00:08:35,360
We can actually run that.

157
00:08:36,600 --> 00:08:41,390
We have good morning, so you've seen
the pluses before for catanation purposes.

158
00:08:41,390 --> 00:08:42,240
But we can also put this.

159
00:08:42,240 --> 00:08:49,600
We can put greeting *=far so
it's actually replicating by repetition.

160
00:08:49,600 --> 00:08:52,860
The current contents of the string
if you actually print that out.

161
00:08:52,860 --> 00:08:55,160
You can actually run that.

162
00:08:55,160 --> 00:08:56,260
And we get good morning, five times.

163
00:08:56,260 --> 00:08:58,900
And we could've added a space here.

164
00:08:58,900 --> 00:09:02,630
Then run them again if you wanna them a
little bit more nicely across the screen.

165
00:09:02,630 --> 00:09:04,890
And you can see it's repeated five times.

166
00:09:04,890 --> 00:09:07,930
They're the only binary operators
that actually work with strings.

167
00:09:07,930 --> 00:09:10,920
Now there's five more binary operations
that we haven't yet looked at, but

168
00:09:10,920 --> 00:09:12,320
we're gonna leave those for later video.

169
00:09:12,320 --> 00:09:14,790
I'll actually just paste you a list
of what they are on the screen now so

170
00:09:14,790 --> 00:09:15,770
you can actually see them.

171
00:09:18,030 --> 00:09:19,300
So we've seen some of them.

172
00:09:19,300 --> 00:09:20,330
We've seen a lot of them.

173
00:09:20,330 --> 00:09:23,250
But some of these other ones here, less
than, less than, equals, greater than,

174
00:09:23,250 --> 00:09:25,980
greater than,
equals ampersand equals, and so on.

175
00:09:25,980 --> 00:09:29,430
So we'll actually see those and
be talking about those in a future video.

176
00:09:29,430 --> 00:09:30,410
So that's the end of this video.

177
00:09:30,410 --> 00:09:33,260
In the next video, it's time for
a section challenge.

178
00:09:33,260 --> 00:09:36,150
So, we're gonna summarize what we've done
to date in this section of the course, and

179
00:09:36,150 --> 00:09:40,010
then we're actually gonna come up with a
challenge to hopefully help you understand

180
00:09:40,010 --> 00:09:42,420
all the concepts that you've
actually learned in this section.

181
00:09:42,420 --> 00:09:43,670
So, I'll see you in that next video.

