In this section, we shall introduce a Python programming language and then we will start with variable
types and basic operators for the variable types and the python programming language.
We have numbers, strings, lists, tuples and dictionaries, and for the basic operators we have arithmetic
operators like plus negative divided by modulo floor exponential.
And for the comparison operators, we have this assignment operators this, membership operators this
and I don't know the operation operators this.
So let's get started.
Let's consider this variables which are created in Python.
We don't need to explicitly give the type of variable we are creating and many other programming languages.
You may have to see, for example, and the variable name.
Equals C six.
And if you take this variable name to B equals a string later on.
It's not going to work.
Now in Python.
This is not necessary.
All you need to do is just give it a variable name.
So in this case, we have the variable name equals six.
We can have a variable save our two equals this string.
We can have another variable var three equals.
See this list?
We could have this list.
And we could have on a variable save our for which is a dictionary so we could have this we're going
to have.
One.
We'll give you one.
We have yet to.
And so no matter what we assign to a variable, the variable automatically gets its type from what is
assigned to.
And then just like any other programming language, we will pin our data to the user.
So yeah, for example, we could bring out variable name.
So we have variable name.
And there we go.
So we print out this variable name and it and variable name equals six pin out actually six.
Now the other ways to format in this print function, you could put a message before the variable name
so you could have here the name of this variable.
You can see the content.
Of this variable is equals this.
So this message is in this double quotes.
And then we have a comma followed by the variable name.
And once we do this, we're going to have this message, which is this.
So we have this bag which is coming from this.
String here, and then the variable name follows.
And since the values start in this variable, variable name is actually equal, six six is printed out.
Now there are also ways of formatting this.
You could have, for example, the content ease and you could do this.
So you have this curly braces and then here you have that format instead of this comma, you could put
that format.
So we have the format variable name.
So we could have the content is of this variable.
Now let's take this away.
Let's take this is and now you find that this is going to be replaced with this variable name.
So there we go.
The content is six of this variable.
So because we put this curly braces and yeah, we put this format, that format, we have the variable
name in and that follows.
So we could always do this, we could have this other curly braces and then we just make sure we put
it in this order.
So yeah, for example, we could put var two and there we go.
So the content is six comma string of this variable.
All of this variables.
So that it could also continue, but in this is making sure we keep the order.
So yeah we have for example viral for so we have the content is six string and this of this variables.
So that's actually how we format the sprint.
And the sprint is very helpful as it not only helps us see this data, but is very helpful to in debugging
your functions, whatever program you're writing.
Now let's come back and look in more detail on this numbers.
We're going to look at the end and the float as these are the two most common type of numbers which
are all working within this course.
What could declare an end like see number equals five and we have number C one.
Let's take this a bit to a yeah, we have number one equals five.
This number equals 8.0.
Now, once you have this, you automatically seeing that this variable that the of itself type float.
And once you have this, you're automatically saying this variable is of that int.
So this is an integer and this is a float.
It could also have a long and a complex number, but we shall work with this on this now.
So bringing this out, we have print.
The number one is this and the number?
So is that.
So for mine in this, we have number one and number two.
So there we go.
The number one is five and the number two is 8.0.
Then the second variable that we should have a working on is the string for strings.
It also tries to define it with this double quits.
So while as we have this, we could see our string.
Could see our string.
Is this in the double quotes?
And there we go.
Now we thought, okay, yeah.
We're supposed to give this the equal sign.
So reloaded.
And we have this Oracle print out string.
So we have the string.
And now what if we're interested in just getting this first element?
Finding this first element?
We have to know that in the pattern programming language, just like many other languages, we start
having this index from zero instead of one.
So if we're looking for the first element, we're going to have to select the index zero.
And to select this index, we have to use the square brackets.
So we have a string of zero which gives us this.
Oh.
Now, if you are looking for this element of this, dear, we could count zero one, two, three.
The space is also a character, so we have zero one, two, three, four, five, six, seven, eight,
nine, ten, 11, 12, 13, 14, 15, 16, 17, 18, nine, 20, 21, 22, 23, 24, 25, 26.
So we place this between the six and we have the.
And that's exactly what we do to get whatever character we have in the string.
Now, if you're interested in getting the portion of a string C interesting.
Get in this position from this.
Oh, to say this, you would have to use this notation.
So yeah, since this is zero one, two, three, four, five, six, seven, eight, nine.
So we'll start from the zero index to the ninth index.
So what we do is we have zero we have this column and then we have ten.
So since we're moving from zero to the ninth index, we go from zero right up to ten.
Now, actually, what happens in Python is if you wanted to go from zero to N, so if you want to go
from zero to C and you have to index from zero to end plus one.
So here you're going to have the string output it, but it's going to go from zero right up to ten minus
one.
I You could consider it like this.
If this is confusing, you could say if you want to go from zero to n minus one, you index from zero
to end.
So that index and this way you show that you're going to have all the elements from zero to n minus
one.
Now index and like this, you're going to have all the elements from 0 to 9.
So in this case, we're going to print.
String zero string one string two string theory string forcing five.
String six string seven.
String eight, answering nine.
So let's bring this out and see for ourselves.
So exactly what we expected.
Now we have this our string up to this not as furious because this may be because of this piece or less
furiously could be reassured that what we have here is going to come 0 to 9 and then we go, we have
this position and now we've add one element we have from 0 to 10.
So let's maintain this.
Now, if you're interested in getting all the elements before then you could just do this and you have
this if you are interested in getting all that.
I mean, before C 15 or 18, you could have this.
So no need to give the initial index.
Now let's say we want to get from the ninth index to the 18 minus warmth index.
You're going to have nine now, unlike this and an index because we have this starting index, which
is in this case, a zero.
We have that index and we have an index.
Generally we are taking these elements from that index.
Who?
An index.
Minus one.
Now, unlike the an index where we go up to any index minus one, the state index actually starts in
whatever index we give it.
So in this case, we're going to start with nine and end at 17.
So let's take something easier for us to count.
Now we'll say we start from 2 to 7.
So in this case, we're going to start from the second index right up to this index.
So let's do this before testing.
So we have 012.
We're going to start from here.
So we're going to have two, three, four, five, six, because we have an seven minus one.
So we have this are up to this.
So this is what we're to bring out.
So let's run this.
And that's exactly what we get.
Now, if you want to print out to the end, suffices to do this.
Once you do this, you start from the second index right up to the end.
And there we go.
You could always find a line of the string so you could print out the line of the string.
So we have yet dedicated to tell us that this string has 38 different characters.
The string, too, has other functions.
That is other simple matters.
You could call like we have string that lower, for example.
Doing this.
You have this local string, that opera.
You're going to send everything to uppercase.
So everything you're saying to uppercase.
Let's say we had this cure so we could better understand what we're saying.
This is a lower phonetic that occurs then to a small Q So everything's ten to lowercase, and that's
exactly what we wanted.
Now let's move to the next variable type.
We're going to work with the very versatile list for list.
For example, we're going to have list one equals C one, two, four.
Now lists are very important, only jojoba, particularly because they can be used to model a matrix.
Let's first start by taking the simple metrics of the simple list, which comes in as a vector.
But then let's bring this out, let's see what we get.
So we have list one, which is this If you interested in getting just a first element, you can have
list zero.
We have that, we have this and then we have that.
Now notice that when we print three, what we have is lists in this out of range.
And that's because this list can only take three different elements.
I want to print this.
We're looking for an element which is not found in this list, and that is because the list has a set,
a number of elements it could contain, but then it lists initially having a set, a number of could
contain doesn't mean it to contain many other elements.
And that's why lists are very useful because they can actually change form.
They are very, very, very versatile.
So we could have, for example, list one that append C an element four or an element eight.
Now you see now that this list three exists, lists are not only made of numbers, we could also have
list made of string.
So we have list string.
The string equals this we have eight.
For example, we could put this string string in list.
We have some white stuff and there we go.
So let's print out this string and see what we get.
We have Listerine.
And that's exactly what we get.
So we find out this list and dig in whatever kind of data type we're going to have to string that up
and see, Hey, Lou, I'm printing this.
We find a halo has been added onto the list.
Now, just like with the strings, you could always have some particular elements of the list selected.
So it could take from zero to say, for example, to you're going to take the zeroth and the first index.
And that's because we're going from that index to an index minus one.
So in this case, we have this we'll see that we have the zero on the first element selected.
So we have eight and this selected.
Now let's take this three.
For example, we have the zero to the second element selected.
We have it this and this does exactly what we wanted.
Noting that at this point the string.
Is actually this.
So there we go.
Now, if you want to get all the elements from a certain index to the end, you simply have to, for
example, in this to print this out, we have the elements from the second index to the end.
So we have 012 from this right up to the end.
Can always get the len of this list.
Does it get a number of elements composed in the list?
So we have Prince line.
String.
Daisy We have four different elements, and that's because a string of metaphor for different elements.
We also initialize and to least as such, we could have a name to list and to list.
Equals this.
So we just need to put in square brackets.
And there we go.
We have this empty list printed out.
Empty list.
So that's it.
And also, there are other ways of initializing the list.
We could have matrix lists or vector lists.
Vector, at least where we initialize it with all zeros, we could have zero times number of elements.
I'm going to have dimension of vector.
Dimension of.
Vector.
Where we could said dimensional vector.
We equal c six and doing this we could print out.
This is vector list equals this.
And doing this we could print out.
Vector at least.
Now we see that this actually gives us just this list with one element zero.
And that is because we've done this wrongly now and correcting that, we have this put outside simply.
So we have this look at this and we're busier.
So doing this now, we actually have the vector initialized with all zeros.
And since this list can be changed, you can have a vector at least vector at least say zero to B equals
nine.
And you could print out vector list.
We find that this has become nine.
Now let's see how to initialize a list to a metrics we have number of Cullen's C equals four number
of rows to be equals three and we can have this metrics list.
Equals zero times.
We have the number of columns.
And then we have all this and this box.
Times the number of rows.
Now, let's look at this again.
We found that in order for us to have this, that is we had this list initialized to six different elements
with all being zeros.
We needed to put this in the square brackets and multiply with set in constants is 6000 and variable
six.
Now, in this case, what we're doing here is what they can all consider in all of this to be that zero.
And we're multiplying by this number of rows.
So let's do this.
And we have the print matrix.
These.
So while we up tenure, is this list made of these three rules?
So we have this first rule made of the zero.
There's zero and this other one zero and the number of rules equals three.
Now, let's replaces zeros with what we had initially.
So instead of this zero, we're going to be having another stuff in here, but with another list replacing
the zero with another list.
So as we do this, let's a matrix list.
And this show equals this.
So you put a zero times number of rows and then yeah, we have metrics list now which I'll see how this
other list is going to replace all the zeros.
Let's print this out.
Print out.
Metrics list initial and then print out metrics list.
So we'll see that this list, made up of four different elements, replaces a zero.
This other list replaces a zero.
This other list is zero.
And this can be seen as some sort of metrics where these are the rules of the metrics.
So we have this rule one, rule two and three.
Now a tuple is similar to a list, but the difference is that once it tuple is defined, it cannot be
changed.
So if we have this tuple, let's call it tuple.
One equals this and instead of the square brackets, we have the symbol brackets that we have there.
One, two, three.
Print is out.
Two for one.
And then we could try to change its values.
See to pull.
1110 equals nine.
Find out we have an error.
Tip would object dozens of but item assignment so it's actually different from list and this has its
values can't be changed so that's it.
We also have dictionaries let's give this dictionary one equals.
So we have this we look up at the dictionary we had defined earlier.
We have this year.
There we go.
Now, to obtain some elements you could have, will print out a dictionary.
Dictionary one to obtain the dilemma with one we have this we see clearly that wants to specify that
we want this element was value is one it gives us a value and once we are in alignment with the values
to it gives us this value.
Now if you keep on doing this, you go to three, find out with two that this three doesn't exist.
So actually, this is some sort of key value pair.
So these are the keys and these are the values keys and the values that set.
Let's look at the python operators we have there from operator, the IS operator, assignment operator,
the membership operator and the identity operators.
So let's look at arithmetic operators.
We're going to have a variable E equals five.
We have B equals seven.
Would have C equals or would take this at, let's say, adequacy plus B this is subtract.
Subtract equals E minus b c divide.
He goes a debate about b.
C we have.
Power equals e to the power of b we have modulo which is equals e modulo b so we have m would be we
have lower divide because we divide it by B and now we could bring all of this.
So we have bring add.
Bring subtract.
Now let's changes of, say, 15.
So we have been add, bring, subtract.
Print divide.
Power.
Lower divide.
There we go.
So let's get the answers we have for this first case will simply add this two variables 15 and 17,
and obviously it gives us 22.
The next we subtract, the next we divide.
And that's why we have this float.
The next would take to the power.
So we have 15 to the power of seven.
This gives us this number.
The next we have the modulo.
Now 15 what seven is actually equals one.
And that's because 15 divided by seven is equals two.
Remember one.
And we know that what a moment is actually what interests us.
So that's why here we have a one and the lower divide actually collects this.
So once we divide this, this is a lower divide, and then this is a more.
So that's why here we have one yet to.
Now, let's look at the others for a comparison.
Operators we shall look at is minded, the one we shall be doing with conditions.
Let's look at the assignment operators.
For this, you could have c e equals eight.
You have B equals five.
And then you wanted to see at C equals C plus E.
Now if you have this all elastic B, there's a, B equals B plus E.
Now, if you print b C that you have 30 and that's because A's eight and B is five.
Now, instead of doing this, you could replace this with plus equals.
So doing this gives the same answer.
So this plus equals is actually equals.
All this is the same as doing this, this plus this.
So B's equals B plus e is the same as the can this.
So if you want to subtract now, if you want to have B equals itself minus any other variable, you
could simply do this for the multiplication this and for the division that.
So that's it.
Now let's look at the next we have for this other operators.
We shall see this one.
We should be working with the conditions and the loops.
So that's it for this section on variable types and basic operators.