Hello.
Welcome back.
So in this lesson we going to look at some operators available to us in python.
This is our last project.
We ended over here with list.
We're going to create a new script from this one.
I'll click file new file and then a press control as to save and I'll name this number three and I'll
call this operators like this now.
And once that is done I can close this one too right.
So we have the basic operators available to us such as multiplication addition subtraction and division.
So let's say we want to add a number we can say equals one plus two.
And indeed we know what the answer is but let's just print and see if indeed it behaves the same way.
So we can print and control as I've come over here run module and what we have is num indeed equals
three and in the same way we can come down here and say num because num asterisk 2.
And just like in other languages the asterisk sign over here is for more application of control as click
here to run run module.
And indeed I'm not printing the NUM so I'm just going to come down here.
Cut the print statement and bring it down here and let's see what we get.
Control is run module and indeed three times to six.
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
remainder equals 10 percentage for let's say we want to print the answer print remainder and we can
hash this one out by commenting it out you can run this save and this indeed is to the remainder of
10 which looks for is two.
So one other way one at a trick I'll show you a nice way to concatenate this there are two ways to concatenate
an integer with a string right integers for instance four plus four plus forty six eight.
But how about four plus.
Boy what would it give us course we shortened out by saying Good plus afternoon equals good afternoon
and four plus four.
Of course eight.
What happens when we see a four plus boy.
Right.
You've got a number and then you've got a string.
How does Python deal with that since Python is so smart.
You do need to declare your own variable is what happens when we throw such a confusion.
How do we run the experiment and see what we get.
So in this print statement I'm going to add an actual string kerosene remainder I'll call this string
remainder like this and then I'll say remainder plus this.
Yes see this is a very innocent thing to do.
I'll click over here to run and on Arrow is thrown.
Why I say it says can only concatenate string to string not integer.
Very smart python.
So in a solution to this is we know this is a number but we can cost this number to a string and we
do that using the s t r function so I can come here and see SDR and then close here as well Contro s
and then run and then now we have remained to we can put an equal sign here for those a few there who
like things been done perfectly report on equal sine and then we run this then we have remainder of
course two.
So this is how we've just written a sentence very simply by in the integer to a string.
Very simple very straightforward.
So now let's see how to do exponents.
How about a power to.
How do we write apart too regularly.
One would say square squared equals let's say twelve like this.
This is what works in other languages but that's not the case or does that's not a case in Python for
race that apart to all we have to do is asterisk austerity to let's say let's print squared and see
what we get.
And we know twelfth race the path to twelve squared is one hundred and forty four we know that.
So we just print and see if indeed that is the answer.
Let's hash this out to avoid confusion in the print so we observe and just this once that is done I
just click over here run mode run module and then okay.
And indeed it's one forty four.
So this is how to do a race that part to hobble race to the path we then of course two becomes three.
But let's try that.
I'll say cubed equals twelve asterisk asterisk three and we can print cubed here print cubed
and we can hash this out and then control s and click here to run the module and of course this is one
thousand seven hundred and twenty eight and indeed twelve to that part three is one thousand seven hundred
and twenty eight.
So this is it.
So in the same way if you want to raise the bar for two or four is the part twelve it becomes asterisk
asterisk and then the particular number.
So very simple.
Now let's play a bit with list Hubbell list.
Can we use these same operators with data structures such as list.
How about we do that and see what we get.
Let's say we have list one here.
Let's declare list one we can see a list one of course one comma to call my three come off for comma
five.
And we can see a list to cause six.
Call my seven comma eight.
Come on nine.
Come on ten.
Right.
Unless a complete list on this call list e course list one plus list two unless unless would come down
here is a print Complete list complete on this call list like this Let's hush our last print statements
out so that we observe just this resort.
Yeah I put a harsh sign her control s run module and let's see.
Right.
This is how it's done it's actually concatenated it.
So when we add to list in this format what happens is we increase the number of columns not a number
of rows.
This is like a matlab column addition.
So what happened is the list.
So list 1 has five columns.
List two has five columns.
When we add Alice want to list two we end up with a list of 10 columns.
So that's how it behaves right.
So let's see other ways that we can print numbers and strings together.
Let's see this simple hash this out.
Let's see the simple print example which is very common as well.
We can see print come down here print
something as simple as.
Number is and I can just put comma to here like this.
And see what it says.
And indeed we have the numbers to write.
You might wonder what happened with this.
Well this was from an integer variable we could actually use this we could use the same method so we
could have rather than type cast remainder to a string.
We could have DSA to call my remainder Okay let's do that now.
The number comma remained like this.
S to save then I'm going to run module and indeed the number remainder is to do so from index to so
don't be confused.
So indeed this is one method of I didn't strings and integers let's let's test out some float.
We've not done any float so let's say a mount
amounts of course zero point seventy five like this and let's come down here and try to print amounts
I can say print into bracket and over here you can see the amount is and then comma amounts and we expect
it to work the same way.
Let's hash this out.
Control is to save and then click.
Click here to run and indeed assess the amount as real point seven five.
So another way of you know I didn't strings and integers is by using the percentage the percentage f
for floats just like we do in C language.
So let's say I come down here and see second amount equals zero point zero zero zero eight nine.
Yeah very random.
We can come here and say print cost.
What will happen is this.
This is this is easy to amount to the end of the sentence.
But what if you want to add a number some way in the middle of the sentence.
Yeah.
The system games you.
There's no way you can do that using this method to the actual way to do it is to use the same method
used in languages like C and let's see what I mean.
So why here.
This is the amount so we can see string like this the amount percentage def is very very small.
And what we have to do this time we don't need a comma or we need this D percentage sign.
And then the name of the variable second amount is very important.
Don't put a comma here.
If you put a comma on Ariel be thrown.
So you keep this the amount percentage F is very very small and outside of the string we have this percentage
variable name.
So control is to save or hash this old one out.
This good example we did construe as to save click by here run module and it says the amount who appoints
researcher 1 is very very small indeed.
So let's see what I meant by pi mistakenly put in a coma.
I put a call my hair.
Let's see.
In C language we do need to call my hair right by Python.
We don't.
So let's try this.
You know this area and see if indeed it was an error or price controls to save.
Click over here run run module and it says invalid syntax.
And indeed the syntax is invalid.
So I need to clean a comma contra s to save.
Click run and then run module and then indeed the amounts you appoint Sure sure sure sure.
One is very very small.
So this it for this very somewhat long lesson on operators.
I hope you understand is very simple python is very simple it just takes you know getting used to it
like most languages actually.
So if you have a question as a tool just send me a message or leave it in the questions area and.
Yeah.
And if you find the course useful please do take some time off to leave a review.
Maybe if I'm moving too fast if that's an issue as well you can send me a message and I can reshoot
some of the video was taken slower.
So this weather is and I shall see you in the next lesson and have a good day.