Hi, everyone, and welcome to the lecture and this lecture and the following lectures, we're going
to discuss variables and data types and we're going to go deep into each variable type and we each lecture,
we're going to have three parts.
First, what will be the theoretical part that will begin in a moment.
Second part will be lots of examples.
And the third part will be practice.
Those of you that get the hang of each topic quickly, I beg you and I really ask you from the bottom
of my heart, please do not stop practicing and do not place practice as like trivial part, because
practice is very important, even if you understand the topics, because once you go further with the
lectures, topics start piling up and you will have to use all the topics altogether.
Of course.
All right.
So let's begin.
So let's begin with variables.
Let's declare let's explain the definition of variables.
So variables are used to store information to be referenced and manipulated in a computer program.
They are also provide a way of labeling data with a descriptive name by using numbers, letters or signs.
All right.
So once looking on the program, it goes like a pyramid.
And the bottom layer of the pyramid are variables because variables with variables, we can assign values
to these variables and later on manipulate them, use them, compare them and so on.
So this part is very crucial for any programmer to understand.
So we have a declaration of variables in Python, slightly different from other object oriented programming
languages.
Once looking on variables, for example, in Java, we'll have like a simple example here.
Don't worry about string variable.
And I'm not just jumping.
Jumping ahead is just an example.
We'll talk about string variables deeply in a moment.
All right.
What I want to focus here that in Java before declaring the variable, we declare the type of the variable
and then, you know, that name is a string type variable and it will have a string value right here.
But once looking on Python, you see the variable declarations straight ahead without mentioning what
type it is.
So just remember, this rule applies for all variables in Python.
You would not see the declaration of type of the variable before it.
And don't worry about it because there are about a million ways of understanding what variable variable
type we're using and the declaration of the type of it is not really crucial.
So let's begin first in line is a string variable as string variable will hold zero or more letters,
numbers, special characters, all or all combination of three.
Also, a string variable could not be manipulated by mathematical actions.
So even if you have a string variable like this, which has a numeric value inside, you cannot do mathematical
action upon it.
So even if you have, for example, name John.
This is the same thing this and this example are both the same, because both of these are strong values
and you cannot manipulate the street value.
So looking on this example seems a bit confusing because I have a number here.
So the number five is the value and the variable name is number.
So why can't I add one number to another?
So you can't do it because it's a string type of a variable.
So now comes and naturally the question up ahead.
So how can I understand and how can I don't identify once I see a string variable ahead of me?
How can I know that this is a string?
How can I know that I can not manipulate on the following variable?
So it's very simple.
String variable can be recognized by having apostrophes.
All right.
At the beginning.
At the end of it.
So once you see this quote marks guys, you know that the value inside is a string value and the string
value cannot be manipulated.
We'll see a few examples straight ahead and will then go straight ahead to practice.
Sorry to see other examples in bicarb.
And then you have your homework that you will practice it a lot.
All right.
So let's talk about conventions.
I mentioned in the previous lecture that we're going to focus on conventions a lot in these lectures.
So I would like to talk about it for a few minutes.
So once we want to declare any variable, even if it's a string or any other type of variable, we have
two simple rules.
So I don't know if you seen the last lecture about conventions are accepted rules by all programmers
globally for naming classes, naming variables and naming methods.
So in PI charm, specifically, by the way, you have these rules set up differently for every programming
language.
So, of course, we're going to talk about Python and in specific of variables in Python.
So how should I know in what way should I give the variable its name?
So we have two basic rules that you need to remember once declaring a variable.
The first one is to give small letters only.
And if having more than two words in the variable name, we put the underscore between the words as
so.
All right.
So for example, you have three variables here.
This is the variable of last name with a value Johnson.
And you can identified that this is a string variable by having this quote marks right here.
And as you can see, it has small letters in each word divided with an underscore.
Right here you have the address variable, which has the value and no value inside and letter value
inside and also a special character inside.
So you have you can have the combination of all three and the right.
You have date of birth.
All right.
This is an example of three words divided with an underscore and having small letters in each word.
And right here you have an example of date of birth.
So these are the best examples.
We can go straight ahead and go to pie charm.
All right.
So open your pie chart and let's try to practice and see some examples.
And once by Chamas opened, just go to file.
And open and if you recall in the previous lectures, we have created a project in C Learning and then
initial project, you can see small black square right here, just click on this folder and then click
open.
OK, sorry.
Then new window.
It doesn't matter if you don't if you don't have the new window pop up, it's OK.
And once we have it open, let me just move it aside for a second, once we have it open, we can begin.
So right here on the left, you have your main folder of the project just right.
Click on it and then choosing you and then file.
Now we're going to create a new python file.
You can see the cursor blinking right here.
You can verify that Python finally selected and just give it a name, starting with a capital letter,
which is also.
A convention of creating new modules or in other words, new files in Python, which we'll discuss in
a detailed way for the wrong, but for now, just create the file with a capital letter that is called
Variables and then hit enter.
All right.
So you can see the file is created and we are located on it.
And that's just start seeing more examples of string variables and manipulations on these variables.
All right.
So first thing, guys, I just want to mention that if you put this sign and everything you write afterwards
will be a comment and pie chart would ignore everything that that is written after this sign.
So it's a really useful tool to leave comments for other developers or even for yourself once you want
to get back to a certain file later on and understand what's written right here.
So let's start with a simple.
Stirring example.
All right, let's start with short string variable.
All right, you see small letters divided with an underscore, then space, then equal Mark and then
quote marks and then right here.
Have a great week, ninja's.
So we have our quote Mark at the beginning and we have a quote Mark at the end.
By the way, have a look that if I delete this quote Mark immediately, I have a line, a red line below
my value.
And if I hover above it, it says to me exactly what's wrong, missing closing quote.
So I don't want to make I'm angry.
So I'm just going to close this quote.
Great.
And now I want to complete my first chunk of code and I want to run it.
Why do I mean by running it?
I want to print this value.
All right.
I have a value here.
And if I click right, click on variables and click run.
Nothing happens here.
You see, nothing happens.
It just states the file that I have just wrong.
And it says process finish with exit code zero.
No errors.
This means no errors, but nothing happened.
But I want something to happen.
I want some action.
So let's just go line below and type in print and let's just insert a the name of the value right here,
the name of the variable.
Sorry.
And once I start typing, you see it's bolded in a pop up so it can out to complete it.
For me this is the magic of by chance.
So you don't need to type everything by yourself.
You can just hit enter boom and then you see it.
Let's try to run it right.
Click again and then run.
Great.
Look at this guys.
It's magic.
You see there is have a great week ninja's right here so you can say congratulations, congratulations
to self because if you completed this part of this path, you have just created your first program in
pie chart.
So that's amazing.
I really mean it.
It's amazing because until ten minutes ago, you didn't know.
Oh, maybe most of you didn't know how to write code in Python.
But right now we have a working program and we have printed our first variable.
So let's go further and study some new things and minimal manipulations or variables.
So let's try to print the first letter of a string variable.
And.
Let's have it like first letter variable and then let's give the value New York City, all right.
And we would like to print the first value of New York City, and we do it by placing square brackets
and placing the number of zero zero states for this place.
This is the zero character index.
All right.
You will hear the term index a lot.
So this character's index is zero, this index character is one and so on and so on.
So we would like to have only the character index zero right here, and that's just to try to print
it.
So you see first letter and I as I just said, you can just hit enter.
All right, let's run it right.
Click, run.
Great, so we can see right here the letter, and so we have just executed the print of the first letter
right here.
So just remember, you remember, guys, that the count starts from zero.
So this one is zero and this one is one and so on.
And let's see some more cool stuff that we can study.
By the way, all of these tricks are seem like maybe a without any goal or why should we learn it?
But believe me, once we go further with it, that shows you're going to use each and every one of these
tricks to create your test cases using selenium.
Um, so let's try to create the mixed, sorry, mixed upper and lower case letter variable, and we'll
do it like this mixed Lantau variable and then just create a shortened sentence with one letter capital
and the next one is small and so on and so on.
Just do as I do.
I'm feeling I'm just finished first grade guys, I would think that if I would be in first grade, my
teacher would be very happy with me, that I have completed the sentence.
All right.
So I just try to print it.
But now we're going to insert here mixed letter enter and then now is the important part, just place
in DOT and you could see it pop up, opens up.
So this pop up is shows you what manipulations he can do on your string variable and you can choose
whatever you want from it.
But for now, we're going to choose the the manipulation, which is lower.
All right.
Let's do it again.
That start typing lower.
All right.
And then we need to do brackets.
Around brackets and right, click on the file, Ron.
All right, so you can see it's printed in a way which is lowercase only for all of these letters right
here.
It took the variable value and converted all the letters here into lowercase values.
So let's try to do another thing, let's try to bring out the length of the that table.
All right.
Let's try to print out the length of this variable.
So just type in print and then Len.
Enter and inside these brackets, just take this variable double click it control, see to copy place
right here, control veto based and let's see what happens.
Run.
Whoa, you see it?
It counted all a number of letters right here and it gives us the number twenty four because we have
twenty four characters inside this string variable.
This is a very useful trick.
We'll use it a lot in test cases later on.
And you need to understand guys that you might see it is playing like words and why do we need to manipulate
them?
But once you go into a website and you would like to verify that a certain text appears there, you
you would really want to use string variables and to verify certain things and to verify, for example,
if a signing pattern appears and if sign out exists or a certain booklist or a certain header appears.
So you would use a string variables and string variable manipulations a lot.
So let's do another thing, let's try to use a variable with a combination of simple text inside a print
commands, so let's create a very first of all, let's give a comment for the upcoming action use plus.
Sign inside a print.
Commands, let's create a new variable, which is first name, and let's put the value inside, David,
and let's try to present the following thing.
All right.
Before before heading, heading, going ahead.
Just I want to say just one thing.
You see the sprint action, you see the sprint action.
You can do two things.
You can put a variable inside.
For example, take this first name and put it inside.
But you can also just put brackets sorry, quoting marks here and write anything you want in here.
So before applying this manipulation, let's just sprint this thing right.
Click run.
You see it straight ahead, what you put inside so you can either put this variable inside the print
or you can just or you can just put the value straight ahead.
So what we're going to do is to do the combination of both.
So put your quote marks and type in first name is then space and then two, that's in space.
And then after the quoting marks, just put another space and here add the plus mark, because we want
to add a variable to the sprint action.
So you have to put it after the quoting marks and then just copy this control C and control V, place
it right here.
And now we try we'll try to print this sentence with the combination of this variable all together.
So let's run it.
Wow, you see, now you can see the combination of these both things you can't you have here a plain
text between these quoting marks and then you have added a variable afterwards.
And what if we would like to take it very well and replace certain letters with other letters?
Let's try to do that right.
So replace a part of a string.
So let's go call this variable first serial number, which will be ABC and capital letters.
One, two, three.
And then add the prince commands and add the text changed serial number.
Just plain text, then space then plus then add here first serial number.
Same as we did before, and then that again, you see the lower the lower manipulation here.
So now we're going to use the replacement ablation.
You can even choose it with your mouse and double click it.
And then, of course, we replace inside these brackets.
And right here, just put this single quote, Mark and inside just place what you would like to replace.
I would like to replace the one, two, three values and then put a.
A coma and right after the coma, we would set what value we would like to replace it with.
So I would like to replace the one, two, three with four or five, six so anyone can guess what should
we get once we print it?
All right, once we printed, I'm I'm expecting to get A, B, C, four or five, six, because I want
to replace these three values.
All right.
Right here.
Replace these three values.
Who is with these three values, by the way, it's important for me to mention that all the manipulations
that we doing inside the Brint have no effect on this variable.
This variable stands still and is not changing.
We are just changing what we see inside the print.
So this stands still and not changing at all.
All right.
Same as here.
All right.
This variable stand stays with these mixed letters.
Were just printing them in an ordered way.
But it's it still stays in.
It makes way if we take the the variable and print it without the lower.
So this variable stays the same.
So let's try to print it and replace one, two, three, four or five, six.
Just right.
Click and one.
And as you can see here, sorry, guys, let's try to make it a bit more orderly space here and two
dots in space again.
Let's try it again because it doesn't look very good for the for the icier.
And there you have it, we have changed your number with ABC four, five, six, exactly what we wanted
to replace these three numbers.
All right.
Because this replay section takes the value from this variable and replaces it with a new one.
So it takes it takes the value from the variable and changes it to a new one and prints it.
So let's try to do a different thing, replace a part of a string.
Twice.
All right, so let's do second, that's a new it's a new variable, the second serial number and let's
call it a, B, C, one, two, three, and ABC again and now.
All right.
I would like to do the following thing.
I would like to change.
Let's give it a number because it's a bit confusing.
Let's give it the first.
And he has changed serial number.
Second to that space, then space and plus and then we're going to take second serial number.
I'm always going to remind you that once you see this pop up, you can just hit enter boom and there
are to replace an.
Rackets, and now I'm going to replace the ABC.
All right, the ABC here appears twice, once here and once you I would like to replace ABC twice.
So what the code does is takes the variable and start scanning it from the beginning to the end.
And once he finds the ABC, once he replaces it and then he goes further, he sees it twice and he presses
he presses this one as well.
So this is what we're going to show right here.
All right.
So let's do this.
ABC, comma.
And let's replace it with Z, Z in both places that we want and then do another Colma and then place
the number two here.
This is the number of times we would like to change ABC in the spring.
So we would like to replace it once and twice here.
With Z Z value, so right, click on this one and run, whoa, you see it, you see you guys.
It took the variable of ABC one, two, three, ABC and replaced two times the ABC with Z values.
And let's try to do one last thing, which is really cool, let's try to do the following thing.
Let's say let's create a new variable, which will be that before it.
It's important that we give a note, take apart.
Of a variable, according to specific, expert, specific.
Indexed indexes, index and places and.
All right, so before we do that part, let's go a little bit back to this part.
And right here we took the index zero am off this string.
All right.
You can see the square brackets right here.
And we took the index zero, meaning this letter.
So this is index zero and this is the index one and this is index two.
So I would like to take not only the first not only one place, but I would like to take a range.
Let's take a part of a variable called the specific index range.
All right.
So let's do it.
Let's call it a range of
indexes.
And let's take the second serial number enter and then let's place the square brackets and let's place
year zero, two dots and three.
And let's try to present the range of indexes.
All right, so what we are waiting to see is the printout of indexes between the places between zero
and three.
So there you have it.
We have printed the values in the zero place in the first place and in the second place until we got
to the third place, which is not included.
All right.
So we printed all the values in the index is between zero and three, while three is not included.
And we have it right here.
So by now, guys, if you have followed my lecture, you are having pretty much domination in the knowledge
of knowing string values.
You now familiar with manipulation, with multiple manipulations upon string values.
And let's do one last thing.
Combine adding words like that, adding.
Spaces between multiple variables imprint.
So let's do it, by the way, maybe you were asking yourself, why do I use print all the time?
Because print is the way of programmers to see the result, because, for example, if I do the manipulation
like here, I can't really know what's happened behind the curtain, what happened behind the scene.
So if I printed, then I can see it.
But before I if I'm not printing it, I'm not really sure what happened.
So I always use print action to see if the manipulation which is here really occurred.
So let's try to do this.
The following thing.
That's three variables, or in other words, three words.
All right.
The first word will be think second word would be you.
And then Third World would be.
Ninja's.
And then let's try to print it all together with a plus sign you see right here, you have a plus sign
once adding a variable.
So the first variable comes without a plus sign because it's the first one.
And then we add the second.
And plus and then we had the third and last sprint that anyone can guess what will happen, would it
printed correctly?
So let's try to print it.
Oh, boy, oh, boy, we have trouble here.
You see, we have no spaces between the words and it's not good.
It's not good.
It's even worse than this thing right here.
Like, if you your teacher would catch you writing this thing, you will get into trouble.
So we have to fix it quickly.
So we have to waste and adding spaces here.
So the first way would be the following.
You see here the first ring.
So we have opening world marks and closing both marks.
But what would happen if I would add a space space right here and the space right here?
So we have the first word and then we would have space at the end of it.
And then we have Second World and we have the space at the end of it, and then we have the Third World.
I think we will be all right.
All right.
So you see here, guys, amazing.
So once you have the space right here, you can see the sentence printed correctly.
So this is one way to do it.
But there is another way, and I'll show you that one as well.
So here we have the first word and right after we have the second word and in between, if I leave it
the space like this, so the program would not recognize that we have a space.
You see, it doesn't recognize because this space is not mentioned inside the prints.
So what you want to do is to add another plus here and to add like you can write here, whatever you
want.
But I want I don't want to write you anything.
I just want to do the space.
All right.
So you see here in between, you have a space and I would like to do it one more time in here.
And Espace.
So now you have space in between words and this is great, so let's try to print it.
And there you have it, you have spaces between words in a second in a second way, and this basically
concludes our our part of examples for string variables.
I hope you enjoyed the video.