1
00:00:00,690 --> 00:00:05,220
In this picture, I want to continue the discussion that we started in the previous lecture where we

2
00:00:05,220 --> 00:00:12,330
talked about data types and types to looking at the same documents from the Python, three documentation

3
00:00:12,330 --> 00:00:15,230
as the one we were looking at in the previous lecture.

4
00:00:15,630 --> 00:00:20,090
And this time I want to focus on some example operators.

5
00:00:20,730 --> 00:00:26,640
So let's have a look at the numerical data types, integer, smooth and complex.

6
00:00:26,640 --> 00:00:34,530
And you can see that here there is a list of operations or compatible operators that can act between

7
00:00:34,530 --> 00:00:40,530
two data types to integers, for example, or an integer and a floating point number, so long as they

8
00:00:40,530 --> 00:00:41,830
are of the same category.

9
00:00:42,060 --> 00:00:50,400
These operators can work so we can add, subtract, multiply, divide the floor quadrant, remainer

10
00:00:50,400 --> 00:00:51,090
and so on.

11
00:00:51,280 --> 00:00:58,560
So all those operators are compatible between anti's, float's and complex numbers.

12
00:00:59,100 --> 00:00:59,720
But this more.

13
00:00:59,730 --> 00:01:05,580
Let's have a look at perhaps some text sequence operators.

14
00:01:05,580 --> 00:01:07,560
So obviously text.

15
00:01:08,440 --> 00:01:15,640
It's not a number, but you can see that there are operators such as capitalize or case fall to capitalize

16
00:01:15,640 --> 00:01:25,480
or return a string with the first character being capitalized as a count operator tells us how many

17
00:01:25,960 --> 00:01:28,120
characters exist in a string.

18
00:01:28,120 --> 00:01:35,560
And there's various parameters that allow you to configure this operator to work the way that you want

19
00:01:35,560 --> 00:01:37,810
it to work and and so on.

20
00:01:37,810 --> 00:01:43,920
There's plenty more of a look at one more and for example, sequence stereotypes.

21
00:01:43,930 --> 00:01:47,330
Let's have a look at the lists.

22
00:01:47,350 --> 00:01:53,260
And you can see there are operators such as Sort for Topal that are.

23
00:01:54,360 --> 00:02:05,220
Operators that allow you to extract, for example, a particular item out of a list or add an item into

24
00:02:05,220 --> 00:02:05,790
the list.

25
00:02:07,140 --> 00:02:07,950
And so on.

26
00:02:07,960 --> 00:02:18,890
So the thing to remember about operators is that some of them appear as a single symbol like this to

27
00:02:18,930 --> 00:02:20,800
give less than operator.

28
00:02:21,150 --> 00:02:31,410
Others appear as a function at the end in the way that all operate is implemented internally, implemented

29
00:02:31,410 --> 00:02:32,880
as a function.

30
00:02:34,320 --> 00:02:40,920
And another thing that is interesting to notice is that in Python, there is a module called Operator

31
00:02:41,340 --> 00:02:50,940
that provides alternative functions that do things such as test for equality or less than equality or

32
00:02:50,940 --> 00:02:53,610
that allow you to add or subtract.

33
00:02:53,640 --> 00:03:01,470
You can see here all of those functions that are part of the operator module allow you to operate between

34
00:03:01,470 --> 00:03:04,650
two numbers or two numerical stereotypes.

35
00:03:04,680 --> 00:03:06,640
I'm going to demonstrate some of those in a moment.

36
00:03:07,830 --> 00:03:15,240
So needless to say that Python has a huge variety of operators that act on data.

37
00:03:15,810 --> 00:03:17,280
Let's have a look at an example.

38
00:03:18,000 --> 00:03:28,860
I'm going to go back to the main documentation for the building teletypes and have a look at the numerics

39
00:03:29,370 --> 00:03:29,990
right here.

40
00:03:30,870 --> 00:03:34,440
So let's try out a couple of these.

41
00:03:34,980 --> 00:03:39,240
You've already seen, for example, how you can add two numbers together.

42
00:03:41,140 --> 00:03:43,640
Using the additional Parado can move things.

43
00:03:43,660 --> 00:03:44,620
Side by side.

44
00:03:47,590 --> 00:04:00,970
You can divide, he can get the remainder of the shine, which is one, we can get the actual value

45
00:04:03,760 --> 00:04:04,660
and so on.

46
00:04:05,050 --> 00:04:07,960
You can also act between strings.

47
00:04:13,020 --> 00:04:21,070
And you can have two strings stuck together, concatenated, let's have a look at another one.

48
00:04:21,880 --> 00:04:28,170
Speaking of strings, should we look at string methods and have a look at this capitalization method?

49
00:04:28,180 --> 00:04:39,220
So let's say that we have a string, such A, B, C, D, and then we apply the capitalized operator.

50
00:04:40,280 --> 00:04:44,740
Help us build it properly, and that will give you a Navy SEAL with a Capital A..

51
00:04:45,200 --> 00:04:49,510
So this is how these operatives can work.

52
00:04:49,850 --> 00:04:51,770
Do one more here count.

53
00:04:52,300 --> 00:04:57,870
So I'm going to go for a game A, B, C, D, this time count like that.

54
00:04:59,770 --> 00:05:01,390
All right, so I've made a mistake.

55
00:05:02,710 --> 00:05:04,130
Are you OK?

56
00:05:04,170 --> 00:05:11,530
So it helps to read the instructions so you can see that count takes at least one argument as per the

57
00:05:12,550 --> 00:05:16,080
documentation here and it to provide the sub.

58
00:05:16,660 --> 00:05:22,600
So let's see how many A's are contained in this string.

59
00:05:22,610 --> 00:05:24,240
So this is what I'm looking for.

60
00:05:24,250 --> 00:05:30,300
And this is telling me that there is one A but what if I'm looking for a B?

61
00:05:30,310 --> 00:05:33,280
So how many pages of a B one?

62
00:05:33,620 --> 00:05:37,600
What about a D this year?

63
00:05:38,380 --> 00:05:41,890
I said this is just an example operator and how you can use them.

64
00:05:41,890 --> 00:05:43,680
Just picking up in random here.

65
00:05:44,020 --> 00:05:48,220
But I do want to show you one more interesting feature.

66
00:05:48,220 --> 00:05:55,270
As I said, Python is very popular and it allows you to do the same thing in multiple ways.

67
00:05:55,270 --> 00:05:56,950
Sometimes it's a good reason behind it.

68
00:05:57,220 --> 00:06:04,510
Usually, for example, the reason can be efficiency or the need to create more self-explanatory code

69
00:06:04,510 --> 00:06:05,110
and so on.

70
00:06:05,110 --> 00:06:09,420
There's always a reason behind the need to do the same thing in multiple ways.

71
00:06:09,820 --> 00:06:13,840
So I mentioned earlier that there is a module called Operator.

72
00:06:13,840 --> 00:06:16,930
And what you can do with this is you can first imported.

73
00:06:17,800 --> 00:06:20,520
I'm just going to clean up before I do this.

74
00:06:20,530 --> 00:06:28,490
Just clear the show and then you can go ahead and import the operator module.

75
00:06:28,840 --> 00:06:40,510
Now you can use any of those functions to operate between the parameters between A and B. So instead

76
00:06:40,510 --> 00:06:53,860
of saying one last one, you could say operator, add one and one that will give you to see exactly

77
00:06:53,860 --> 00:06:57,200
the same things, just a different way of doing this.

78
00:06:57,250 --> 00:07:03,400
So here is the ad operator returns A and B for two numbers.

79
00:07:04,310 --> 00:07:07,310
This multiplication, so let's try that.

80
00:07:12,020 --> 00:07:14,860
Make it a bit more interesting, three times five.

81
00:07:15,940 --> 00:07:16,650
What happened here?

82
00:07:16,870 --> 00:07:23,800
Are you got an extra T that should be for multiplying like.

83
00:07:25,630 --> 00:07:32,770
Now, let's switch over to macro python on the of it, too, so I'm going to go into tools, options

84
00:07:32,770 --> 00:07:37,350
and change my interpreter to the especially to connected to the correct port.

85
00:07:37,960 --> 00:07:38,660
OK.

86
00:07:38,710 --> 00:07:47,040
And now I'm running Micro Python, so I'm going to try and play around with some operators.

87
00:07:47,050 --> 00:07:49,930
Of course, one plus one works

88
00:07:52,570 --> 00:07:54,280
to the plus operator works.

89
00:07:54,820 --> 00:07:56,440
Let's try the string operator.

90
00:07:58,910 --> 00:08:00,360
That works, OK, no problem.

91
00:08:00,410 --> 00:08:07,310
So all of the building operators will work, but what about the operator module?

92
00:08:07,760 --> 00:08:17,810
We're going to import operator and you can see that there's no such module named operator in Micro Python.

93
00:08:18,860 --> 00:08:25,180
Obviously, this is not a module that is built into micro python, unlike, say, Python.

94
00:08:25,640 --> 00:08:27,970
But we can go ahead and install it.

95
00:08:27,990 --> 00:08:31,820
And this is an opportunity to show you how to do something like that from here on.

96
00:08:31,820 --> 00:08:41,420
Piper and I did a search for operator, angiostatin operator in the search box in here and the micro

97
00:08:41,420 --> 00:08:43,580
python operator module came out.

98
00:08:44,040 --> 00:08:54,440
So what I can do next is I can copy the name of this module going to Sony to manage packages and then

99
00:08:54,440 --> 00:08:59,360
search for this particular package on pipeline.

100
00:09:00,110 --> 00:09:01,100
And here it is.

101
00:09:03,200 --> 00:09:05,300
And I can click on Insta.

102
00:09:09,620 --> 00:09:19,500
So the installation process will bring the necessary file across stored inside the folder on my desk,

103
00:09:19,510 --> 00:09:20,020
32.

104
00:09:20,090 --> 00:09:28,910
Now I can try to input operator again and now it worked without any complaints and I can use it just

105
00:09:28,910 --> 00:09:31,390
like I did in my example earlier this year.

106
00:09:31,400 --> 00:09:34,640
Addition to one and two gives us.

107
00:09:35,090 --> 00:09:36,610
OK, what have I done?

108
00:09:37,970 --> 00:09:42,170
OK, so there's no attribute and let's check it out.

109
00:09:42,200 --> 00:09:43,370
This is a nice thing here.

110
00:09:43,370 --> 00:09:51,340
We can drill inside a python file or any python file to see what is going on there.

111
00:09:51,590 --> 00:09:57,730
And you see that there is no such attribute at all or there's no function.

112
00:09:57,740 --> 00:10:07,460
And so this particular python operator, Morschel, does not have the add function that the C version

113
00:10:07,460 --> 00:10:09,450
of the same module does.

114
00:10:09,800 --> 00:10:18,470
So what is available for me to use is one of those first try out LTE, whether A is less than B.

115
00:10:19,130 --> 00:10:20,900
So again, operator.

116
00:10:25,610 --> 00:10:33,020
Dode guilty, let's say, to command center, and they should.

117
00:10:33,970 --> 00:10:35,740
Two is smaller than seven.

118
00:10:37,260 --> 00:10:43,020
OK, so I'm going to leave it at this in this lecture, I simply wanted to show you that there's a large

119
00:10:43,020 --> 00:10:51,810
number of operators that allow you to do operations between data types, as well as the ability to conduct

120
00:10:51,810 --> 00:10:58,860
operations using modules such as the operators module that we played around a bit earlier.

121
00:10:59,480 --> 00:11:03,750
All of the basic operators that are available in Python are also available there.

122
00:11:03,780 --> 00:11:05,380
And those are the ones that will be.
