In this picture, I want to continue the discussion that we started in the previous lecture where we
talked about data types and types to looking at the same documents from the Python, three documentation
as the one we were looking at in the previous lecture.
And this time I want to focus on some example operators.
So let's have a look at the numerical data types, integer, smooth and complex.
And you can see that here there is a list of operations or compatible operators that can act between
two data types to integers, for example, or an integer and a floating point number, so long as they
are of the same category.
These operators can work so we can add, subtract, multiply, divide the floor quadrant, remainer
and so on.
So all those operators are compatible between anti's, float's and complex numbers.
But this more.
Let's have a look at perhaps some text sequence operators.
So obviously text.
It's not a number, but you can see that there are operators such as capitalize or case fall to capitalize
or return a string with the first character being capitalized as a count operator tells us how many
characters exist in a string.
And there's various parameters that allow you to configure this operator to work the way that you want
it to work and and so on.
There's plenty more of a look at one more and for example, sequence stereotypes.
Let's have a look at the lists.
And you can see there are operators such as Sort for Topal that are.
Operators that allow you to extract, for example, a particular item out of a list or add an item into
the list.
And so on.
So the thing to remember about operators is that some of them appear as a single symbol like this to
give less than operator.
Others appear as a function at the end in the way that all operate is implemented internally, implemented
as a function.
And another thing that is interesting to notice is that in Python, there is a module called Operator
that provides alternative functions that do things such as test for equality or less than equality or
that allow you to add or subtract.
You can see here all of those functions that are part of the operator module allow you to operate between
two numbers or two numerical stereotypes.
I'm going to demonstrate some of those in a moment.
So needless to say that Python has a huge variety of operators that act on data.
Let's have a look at an example.
I'm going to go back to the main documentation for the building teletypes and have a look at the numerics
right here.
So let's try out a couple of these.
You've already seen, for example, how you can add two numbers together.
Using the additional Parado can move things.
Side by side.
You can divide, he can get the remainder of the shine, which is one, we can get the actual value
and so on.
You can also act between strings.
And you can have two strings stuck together, concatenated, let's have a look at another one.
Speaking of strings, should we look at string methods and have a look at this capitalization method?
So let's say that we have a string, such A, B, C, D, and then we apply the capitalized operator.
Help us build it properly, and that will give you a Navy SEAL with a Capital A..
So this is how these operatives can work.
Do one more here count.
So I'm going to go for a game A, B, C, D, this time count like that.
All right, so I've made a mistake.
Are you OK?
So it helps to read the instructions so you can see that count takes at least one argument as per the
documentation here and it to provide the sub.
So let's see how many A's are contained in this string.
So this is what I'm looking for.
And this is telling me that there is one A but what if I'm looking for a B?
So how many pages of a B one?
What about a D this year?
I said this is just an example operator and how you can use them.
Just picking up in random here.
But I do want to show you one more interesting feature.
As I said, Python is very popular and it allows you to do the same thing in multiple ways.
Sometimes it's a good reason behind it.
Usually, for example, the reason can be efficiency or the need to create more self-explanatory code
and so on.
There's always a reason behind the need to do the same thing in multiple ways.
So I mentioned earlier that there is a module called Operator.
And what you can do with this is you can first imported.
I'm just going to clean up before I do this.
Just clear the show and then you can go ahead and import the operator module.
Now you can use any of those functions to operate between the parameters between A and B. So instead
of saying one last one, you could say operator, add one and one that will give you to see exactly
the same things, just a different way of doing this.
So here is the ad operator returns A and B for two numbers.
This multiplication, so let's try that.
Make it a bit more interesting, three times five.
What happened here?
Are you got an extra T that should be for multiplying like.
Now, let's switch over to macro python on the of it, too, so I'm going to go into tools, options
and change my interpreter to the especially to connected to the correct port.
OK.
And now I'm running Micro Python, so I'm going to try and play around with some operators.
Of course, one plus one works
to the plus operator works.
Let's try the string operator.
That works, OK, no problem.
So all of the building operators will work, but what about the operator module?
We're going to import operator and you can see that there's no such module named operator in Micro Python.
Obviously, this is not a module that is built into micro python, unlike, say, Python.
But we can go ahead and install it.
And this is an opportunity to show you how to do something like that from here on.
Piper and I did a search for operator, angiostatin operator in the search box in here and the micro
python operator module came out.
So what I can do next is I can copy the name of this module going to Sony to manage packages and then
search for this particular package on pipeline.
And here it is.
And I can click on Insta.
So the installation process will bring the necessary file across stored inside the folder on my desk,
32.
Now I can try to input operator again and now it worked without any complaints and I can use it just
like I did in my example earlier this year.
Addition to one and two gives us.
OK, what have I done?
OK, so there's no attribute and let's check it out.
This is a nice thing here.
We can drill inside a python file or any python file to see what is going on there.
And you see that there is no such attribute at all or there's no function.
And so this particular python operator, Morschel, does not have the add function that the C version
of the same module does.
So what is available for me to use is one of those first try out LTE, whether A is less than B.
So again, operator.
Dode guilty, let's say, to command center, and they should.
Two is smaller than seven.
OK, so I'm going to leave it at this in this lecture, I simply wanted to show you that there's a large
number of operators that allow you to do operations between data types, as well as the ability to conduct
operations using modules such as the operators module that we played around a bit earlier.
All of the basic operators that are available in Python are also available there.
And those are the ones that will be.