1
00:00:00,940 --> 00:00:01,260
Hello.

2
00:00:01,270 --> 00:00:02,080
Welcome back.

3
00:00:02,080 --> 00:00:07,240
So in this lesson we going to look at some operators available to us in python.

4
00:00:07,240 --> 00:00:08,850
This is our last project.

5
00:00:08,980 --> 00:00:11,140
We ended over here with list.

6
00:00:11,260 --> 00:00:13,580
We're going to create a new script from this one.

7
00:00:13,600 --> 00:00:21,310
I'll click file new file and then a press control as to save and I'll name this number three and I'll

8
00:00:21,310 --> 00:00:24,750
call this operators like this now.

9
00:00:24,920 --> 00:00:29,220
And once that is done I can close this one too right.

10
00:00:29,230 --> 00:00:38,060
So we have the basic operators available to us such as multiplication addition subtraction and division.

11
00:00:38,080 --> 00:00:42,430
So let's say we want to add a number we can say equals one plus two.

12
00:00:42,550 --> 00:00:49,190
And indeed we know what the answer is but let's just print and see if indeed it behaves the same way.

13
00:00:49,330 --> 00:00:56,440
So we can print and control as I've come over here run module and what we have is num indeed equals

14
00:00:56,440 --> 00:01:05,060
three and in the same way we can come down here and say num because num asterisk 2.

15
00:01:05,110 --> 00:01:12,070
And just like in other languages the asterisk sign over here is for more application of control as click

16
00:01:12,070 --> 00:01:14,020
here to run run module.

17
00:01:14,020 --> 00:01:19,970
And indeed I'm not printing the NUM so I'm just going to come down here.

18
00:01:19,980 --> 00:01:24,390
Cut the print statement and bring it down here and let's see what we get.

19
00:01:24,410 --> 00:01:29,960
Control is run module and indeed three times to six.

20
00:01:30,010 --> 00:01:38,170
So we've got six printed and we can do a module or sign as well we can see a remainder Yeah we can say

21
00:01:38,170 --> 00:01:51,940
remainder equals 10 percentage for let's say we want to print the answer print remainder and we can

22
00:01:51,970 --> 00:02:00,920
hash this one out by commenting it out you can run this save and this indeed is to the remainder of

23
00:02:00,920 --> 00:02:03,550
10 which looks for is two.

24
00:02:03,650 --> 00:02:11,420
So one other way one at a trick I'll show you a nice way to concatenate this there are two ways to concatenate

25
00:02:11,600 --> 00:02:19,440
an integer with a string right integers for instance four plus four plus forty six eight.

26
00:02:19,440 --> 00:02:21,420
But how about four plus.

27
00:02:21,420 --> 00:02:28,670
Boy what would it give us course we shortened out by saying Good plus afternoon equals good afternoon

28
00:02:28,900 --> 00:02:29,980
and four plus four.

29
00:02:29,970 --> 00:02:30,910
Of course eight.

30
00:02:31,070 --> 00:02:33,640
What happens when we see a four plus boy.

31
00:02:33,650 --> 00:02:34,100
Right.

32
00:02:34,100 --> 00:02:38,600
You've got a number and then you've got a string.

33
00:02:38,600 --> 00:02:42,440
How does Python deal with that since Python is so smart.

34
00:02:42,470 --> 00:02:47,780
You do need to declare your own variable is what happens when we throw such a confusion.

35
00:02:47,780 --> 00:02:51,230
How do we run the experiment and see what we get.

36
00:02:51,230 --> 00:02:57,520
So in this print statement I'm going to add an actual string kerosene remainder I'll call this string

37
00:02:57,540 --> 00:03:01,580
remainder like this and then I'll say remainder plus this.

38
00:03:01,610 --> 00:03:04,910
Yes see this is a very innocent thing to do.

39
00:03:04,920 --> 00:03:08,960
I'll click over here to run and on Arrow is thrown.

40
00:03:08,960 --> 00:03:15,710
Why I say it says can only concatenate string to string not integer.

41
00:03:15,710 --> 00:03:17,270
Very smart python.

42
00:03:17,270 --> 00:03:24,020
So in a solution to this is we know this is a number but we can cost this number to a string and we

43
00:03:24,020 --> 00:03:32,150
do that using the s t r function so I can come here and see SDR and then close here as well Contro s

44
00:03:32,750 --> 00:03:41,090
and then run and then now we have remained to we can put an equal sign here for those a few there who

45
00:03:41,090 --> 00:03:47,120
like things been done perfectly report on equal sine and then we run this then we have remainder of

46
00:03:47,120 --> 00:03:47,630
course two.

47
00:03:47,630 --> 00:03:54,830
So this is how we've just written a sentence very simply by in the integer to a string.

48
00:03:54,830 --> 00:03:57,710
Very simple very straightforward.

49
00:03:57,710 --> 00:04:01,290
So now let's see how to do exponents.

50
00:04:01,340 --> 00:04:02,330
How about a power to.

51
00:04:02,330 --> 00:04:04,820
How do we write apart too regularly.

52
00:04:04,820 --> 00:04:12,500
One would say square squared equals let's say twelve like this.

53
00:04:12,500 --> 00:04:19,430
This is what works in other languages but that's not the case or does that's not a case in Python for

54
00:04:19,580 --> 00:04:26,840
race that apart to all we have to do is asterisk austerity to let's say let's print squared and see

55
00:04:26,840 --> 00:04:27,410
what we get.

56
00:04:27,430 --> 00:04:33,450
And we know twelfth race the path to twelve squared is one hundred and forty four we know that.

57
00:04:33,560 --> 00:04:37,310
So we just print and see if indeed that is the answer.

58
00:04:37,820 --> 00:04:44,930
Let's hash this out to avoid confusion in the print so we observe and just this once that is done I

59
00:04:44,960 --> 00:04:48,900
just click over here run mode run module and then okay.

60
00:04:48,920 --> 00:04:51,020
And indeed it's one forty four.

61
00:04:51,050 --> 00:04:59,260
So this is how to do a race that part to hobble race to the path we then of course two becomes three.

62
00:04:59,670 --> 00:05:00,920
But let's try that.

63
00:05:01,460 --> 00:05:13,340
I'll say cubed equals twelve asterisk asterisk three and we can print cubed here print cubed

64
00:05:16,460 --> 00:05:25,010
and we can hash this out and then control s and click here to run the module and of course this is one

65
00:05:25,010 --> 00:05:31,640
thousand seven hundred and twenty eight and indeed twelve to that part three is one thousand seven hundred

66
00:05:31,640 --> 00:05:32,950
and twenty eight.

67
00:05:32,980 --> 00:05:33,670
So this is it.

68
00:05:33,870 --> 00:05:39,800
So in the same way if you want to raise the bar for two or four is the part twelve it becomes asterisk

69
00:05:39,890 --> 00:05:44,190
asterisk and then the particular number.

70
00:05:44,190 --> 00:05:45,940
So very simple.

71
00:05:45,940 --> 00:05:48,510
Now let's play a bit with list Hubbell list.

72
00:05:48,510 --> 00:05:54,240
Can we use these same operators with data structures such as list.

73
00:05:54,330 --> 00:05:56,850
How about we do that and see what we get.

74
00:05:56,850 --> 00:05:58,620
Let's say we have list one here.

75
00:05:59,310 --> 00:06:07,530
Let's declare list one we can see a list one of course one comma to call my three come off for comma

76
00:06:07,540 --> 00:06:08,180
five.

77
00:06:08,740 --> 00:06:13,890
And we can see a list to cause six.

78
00:06:13,900 --> 00:06:15,010
Call my seven comma eight.

79
00:06:15,010 --> 00:06:16,190
Come on nine.

80
00:06:16,370 --> 00:06:17,780
Come on ten.

81
00:06:17,900 --> 00:06:18,750
Right.

82
00:06:18,870 --> 00:06:31,600
Unless a complete list on this call list e course list one plus list two unless unless would come down

83
00:06:31,600 --> 00:06:41,080
here is a print Complete list complete on this call list like this Let's hush our last print statements

84
00:06:41,080 --> 00:06:43,620
out so that we observe just this resort.

85
00:06:43,620 --> 00:06:51,370
Yeah I put a harsh sign her control s run module and let's see.

86
00:06:51,370 --> 00:06:51,910
Right.

87
00:06:51,910 --> 00:06:56,040
This is how it's done it's actually concatenated it.

88
00:06:56,260 --> 00:07:02,110
So when we add to list in this format what happens is we increase the number of columns not a number

89
00:07:02,110 --> 00:07:02,650
of rows.

90
00:07:02,650 --> 00:07:06,140
This is like a matlab column addition.

91
00:07:06,160 --> 00:07:08,080
So what happened is the list.

92
00:07:08,080 --> 00:07:10,920
So list 1 has five columns.

93
00:07:10,930 --> 00:07:13,750
List two has five columns.

94
00:07:13,780 --> 00:07:18,340
When we add Alice want to list two we end up with a list of 10 columns.

95
00:07:18,370 --> 00:07:22,510
So that's how it behaves right.

96
00:07:22,630 --> 00:07:28,180
So let's see other ways that we can print numbers and strings together.

97
00:07:28,450 --> 00:07:30,430
Let's see this simple hash this out.

98
00:07:31,390 --> 00:07:35,650
Let's see the simple print example which is very common as well.

99
00:07:35,650 --> 00:07:38,770
We can see print come down here print

100
00:07:41,520 --> 00:07:43,470
something as simple as.

101
00:07:43,990 --> 00:07:49,440
Number is and I can just put comma to here like this.

102
00:07:51,340 --> 00:07:53,870
And see what it says.

103
00:07:53,980 --> 00:07:57,770
And indeed we have the numbers to write.

104
00:07:57,880 --> 00:07:59,920
You might wonder what happened with this.

105
00:07:59,920 --> 00:08:10,220
Well this was from an integer variable we could actually use this we could use the same method so we

106
00:08:10,220 --> 00:08:14,950
could have rather than type cast remainder to a string.

107
00:08:14,950 --> 00:08:18,920
We could have DSA to call my remainder Okay let's do that now.

108
00:08:19,070 --> 00:08:23,820
The number comma remained like this.

109
00:08:24,060 --> 00:08:32,870
S to save then I'm going to run module and indeed the number remainder is to do so from index to so

110
00:08:32,870 --> 00:08:33,970
don't be confused.

111
00:08:34,160 --> 00:08:41,010
So indeed this is one method of I didn't strings and integers let's let's test out some float.

112
00:08:41,010 --> 00:08:43,780
We've not done any float so let's say a mount

113
00:08:46,400 --> 00:08:54,390
amounts of course zero point seventy five like this and let's come down here and try to print amounts

114
00:08:54,510 --> 00:09:05,610
I can say print into bracket and over here you can see the amount is and then comma amounts and we expect

115
00:09:05,610 --> 00:09:06,780
it to work the same way.

116
00:09:06,870 --> 00:09:09,430
Let's hash this out.

117
00:09:09,810 --> 00:09:13,370
Control is to save and then click.

118
00:09:14,130 --> 00:09:18,840
Click here to run and indeed assess the amount as real point seven five.

119
00:09:19,050 --> 00:09:26,040
So another way of you know I didn't strings and integers is by using the percentage the percentage f

120
00:09:27,300 --> 00:09:30,810
for floats just like we do in C language.

121
00:09:30,900 --> 00:09:42,410
So let's say I come down here and see second amount equals zero point zero zero zero eight nine.

122
00:09:42,480 --> 00:09:44,570
Yeah very random.

123
00:09:44,850 --> 00:09:47,700
We can come here and say print cost.

124
00:09:47,730 --> 00:09:49,390
What will happen is this.

125
00:09:49,800 --> 00:09:53,990
This is this is easy to amount to the end of the sentence.

126
00:09:54,000 --> 00:09:59,000
But what if you want to add a number some way in the middle of the sentence.

127
00:09:59,010 --> 00:09:59,350
Yeah.

128
00:09:59,400 --> 00:10:00,970
The system games you.

129
00:10:00,990 --> 00:10:08,040
There's no way you can do that using this method to the actual way to do it is to use the same method

130
00:10:08,040 --> 00:10:11,160
used in languages like C and let's see what I mean.

131
00:10:11,160 --> 00:10:11,720
So why here.

132
00:10:11,730 --> 00:10:26,650
This is the amount so we can see string like this the amount percentage def is very very small.

133
00:10:27,370 --> 00:10:33,420
And what we have to do this time we don't need a comma or we need this D percentage sign.

134
00:10:33,430 --> 00:10:38,670
And then the name of the variable second amount is very important.

135
00:10:38,680 --> 00:10:39,600
Don't put a comma here.

136
00:10:39,610 --> 00:10:42,460
If you put a comma on Ariel be thrown.

137
00:10:42,460 --> 00:10:50,990
So you keep this the amount percentage F is very very small and outside of the string we have this percentage

138
00:10:51,680 --> 00:10:52,520
variable name.

139
00:10:52,550 --> 00:10:56,560
So control is to save or hash this old one out.

140
00:10:56,570 --> 00:11:03,950
This good example we did construe as to save click by here run module and it says the amount who appoints

141
00:11:03,950 --> 00:11:06,700
researcher 1 is very very small indeed.

142
00:11:06,710 --> 00:11:11,170
So let's see what I meant by pi mistakenly put in a coma.

143
00:11:11,360 --> 00:11:12,470
I put a call my hair.

144
00:11:12,500 --> 00:11:13,230
Let's see.

145
00:11:13,280 --> 00:11:16,970
In C language we do need to call my hair right by Python.

146
00:11:17,000 --> 00:11:17,970
We don't.

147
00:11:18,020 --> 00:11:19,210
So let's try this.

148
00:11:19,210 --> 00:11:24,420
You know this area and see if indeed it was an error or price controls to save.

149
00:11:24,710 --> 00:11:29,890
Click over here run run module and it says invalid syntax.

150
00:11:29,990 --> 00:11:32,780
And indeed the syntax is invalid.

151
00:11:32,780 --> 00:11:36,470
So I need to clean a comma contra s to save.

152
00:11:36,860 --> 00:11:42,680
Click run and then run module and then indeed the amounts you appoint Sure sure sure sure.

153
00:11:42,680 --> 00:11:45,550
One is very very small.

154
00:11:45,740 --> 00:11:52,060
So this it for this very somewhat long lesson on operators.

155
00:11:52,100 --> 00:11:56,930
I hope you understand is very simple python is very simple it just takes you know getting used to it

156
00:11:57,200 --> 00:11:59,030
like most languages actually.

157
00:11:59,030 --> 00:12:04,010
So if you have a question as a tool just send me a message or leave it in the questions area and.

158
00:12:04,920 --> 00:12:05,570
Yeah.

159
00:12:05,690 --> 00:12:10,190
And if you find the course useful please do take some time off to leave a review.

160
00:12:10,280 --> 00:12:16,730
Maybe if I'm moving too fast if that's an issue as well you can send me a message and I can reshoot

161
00:12:16,730 --> 00:12:18,620
some of the video was taken slower.

162
00:12:19,130 --> 00:12:23,690
So this weather is and I shall see you in the next lesson and have a good day.
