Welcome back.
So we've just learned about the first two, well, kind of three, because we also mentioned that there
is such a thing as a complex number in Python, but we talked about the main ones that aren't and float
and there are still a few data types remaining.
But before we get to these, we are missing an important concept, and this is going to be our first
important term in Python and as a matter of fact, in all programming languages.
It's called variables, yep, that's a term.
Now, if this is your first time learning a programming language, you might not know what this means
if this isn't your first time.
Well, this is very simple because all languages have variables.
But what are they exactly?
Well, variables store information that can be used in our programs so we can hold perhaps user inputs
like values.
Maybe when you log into Facebook, you need to hold some information such as your profile picture or
maybe your date of birth in a variable.
Variables are ways for us to store information on our computer.
So let's have a look at this, if we remove this and let's say I'm creating a quiz program.
And this quiz program maybe measures your IQ and let's say you just took the quiz and you found out
that your IQ is 190 quite high.
Good job, but we need to store that information somewhere.
What we can do that with variables so that in Python, all we need to do is name it, whatever you want.
In our case, it will be IQ and we're going to say IQ equals one ninety.
And this IQ here is a variable, it is something that I just completely made up, I could name it whatever
I want, that's a variable, too.
The idea is that once we assign to a variable, that is we're saying one ninety is going to be assigned
to IQ.
I can now use it in my program whenever I want.
For example, I can later on print or make sure it's not cap.
Let's do print IQ.
And if I do that and click run, you see that I can use IQ.
So we can pretend here that a user takes a quiz, finds out their IQ is one night, we can store that
information in this variable and later on when they come perhaps online or try to use the program again,
they don't have to take the quiz all over because, well, we store that information in IQ.
And remember what I said at the beginning, programs are simply data that's being stored, that's being
changed, that's being removed, and that's all programs are and variables are important concepts in
Python and all languages.
Now, variables can also sometimes be called names.
So this could be a name, for example, in assigning a value is also known as binding.
That is where binding the value one Nidhi to this variable so that when we request this variable later
on in our program, our computer knows how to look for this information.
It's going to say, hey, I know what IQ is.
I stored it somewhere, a memory, and it's going to go look for that.
And because it's being bound to a value, it points to this value one.
And remember, this number in memory gets stored as a binary representation in zeros and ones.
Right.
But it doesn't matter to us because however our machine stores it, we don't care.
We just want to be able to retrieve it.
And then when we print it to do well, get one 180 now we're going to be using variables all over the
course.
But on top of just naming variables however we want, there is some best practices around variables
of how you should write good variables.
And as a matter of fact, these are specific rules that the Python community as a whole has that you'll
just have to remember.
So let's have a look at this variables.
And remember, this is the symbol for best practices are what we call snake case.
Snake gas means it's all lower case and then spaces, while they don't exist, we use underscores variables
must start with a lower case or an underscore.
Variables can be anything with letters, numbers and underscores.
But remember, they have to start with lower case and underscore.
That means we can start a variable with a number there.
Also case sensitive.
That means if I create a variable.
But let's say this nakase this variable has a capital E instead of a lower Kacie, there'll be a different
variable.
And then finally, you can't overwrite keywords.
Let's go through these with some examples.
First, a variable has to be in the form of a snake case, that is, if I want to call this user IQ,
I should technically have an underscore here instead of a space just to make sure that a programmer,
maybe I'm working on a team can read this variable.
So that's snake case, you also have to start your variables with either a letter or an underscore.
So I can technically do this and I click run.
Well, that's going to give me an error because I've changed a variable.
So now in order to access that variable, you have to go like this.
Now, underscore in python signifies a private variable, something that will go over later on in the
course.
But usually you're starting your variables with a letter and afterwards, yeah, you can add numbers
if you want in here.
That's no problem.
This is still going to work.
This is a valid variable.
Finally, a variable is case sensitive, so if I do user IQ here and I do capital letters.
I can't access this.
Like this, because while it doesn't exist, again, it's case sensitive, we have to make sure that
we match.
And finally, we don't want to overwrite key words.
What does that mean?
Key words in Python.
Well, they already mean something in Python, for example, this print is a key word.
You can see it highlighted in blue so that if I create a variable saying print equals one ninety and
then I do print.
Print.
Hmm.
Let's see what happens.
We get an error because I can't really assign to this variable, because print already mean something.
Now, I know what you're wondering, what are these key words in Python?
That's a simple Google search away and we'll learn these throughout our course.
If we go to python keywords by three schools, you'll see that we have these key words that each mean
something in Python.
Again, we'll go through these and we'll learn them throughout our course, and if you look, it's not
that intimidating, there's not that many.
So as we practice, you'll start to get familiar with them.
But the easiest way to tell whether it's keyboarder or an important word in in Python.
Well, you see that it's highlighted in blue.
As soon as you create a variable that is unique, it's highlighted in white.
And this will be the case with whatever environment that you're typing code into, as long as it's set
up for Python.
Now, beyond the python key words, there are different things like, for example, the ante for integer
that we've learned.
So, Lisa, we're going to get familiar with so a good rule of thumb for variables is to make them really
descriptive, really say what your intention is, and a good programmer is somebody that's able to name
things really well with their variables.
So if a new developer comes and looks at your code, it's easily understood.
Finally, variables can also be reassigned.
For example, let's say we have IQ here of one 190 and then I decide to perhaps have another variable,
call it user.
And for some reason, I want to assign user age to perhaps have an IQ divided by four.
Is that going to work?
It should write, I'm saying user age is going to equal forty seven point five, I'm using IQ, which
is 190, dividing it by four and assigning it to user age.
I can maybe assign this to another variable called user age or called a and once again.
Run this and it's printing the same thing so you can use variables to store that information and use
it whenever you want.
You can use it in operations, you can use it to reassign it.
Whatever your program needs now, later on in the course, we're going to learn about classes and classes
actually have a different convention than this, but we'll get to that later on.
For now, though, I want to mention two small gotchas with variables that you should be careful with.
For example, there's an idea of constants and constants are those things that never change in a program.
For example, if we wanted to create a constant such as the value of PI, let's say for now it's three
point one for we can have it all in capitals.
And that's going to tell other programmers that, hey, this is a constant this number is not meant
to change.
I mean, we could change it if we want.
There you go.
I just made PI equal to zero, so it was stored as three point one for a memory, but then we overrode
it and reassigned it.
The value of zero.
You can still do that.
But a good convention is that if you see this, that means this number or this value should never be
changed.
Another type of variable that you're going to see, and this is something we'll see later on in the
course are the.
It doesn't look like I just did double underscores here, but it's two underscores.
And we call these Dundar.
And as you can see here, we have some Dundar variables that Python has.
Now, we'll learn more about these later on, but the idea here is that these are meant to be left alone.
You should not touch them.
You shouldn't create a variable with two underscores like this and call it high.
And assign a value.
I mean, you still can, however, this is generally not good practice, so you want to be careful with
that.
But the one thing that I really want you to take away from this is that variables are really important.
Concepts in programming.
Naming variables is one of the most important skills you have as a programmer.
I know it sounds silly, but there's so many times that I read code that is so hard to understand simply
because a programmer is not descriptive enough.
So throughout the course we're going to learn how to name things well so that our code reads like English.
And that's the whole point of writing a code, the point of writing a code is that it's readable and
understandable by other programmers, by the way, to finish off.
I just want to show you one quick trick.
There's also a way that you might see in some code bases that uses something like this.
He calls one, two, three.
And this simply is a way for us to rapidly assign values to variables multiple times, so, for example,
if I do print A, then print B, then print C and I run this.
You see that I get one, two, three, we assign value of one to a value of two to B and value of three
to C.
Just a quick shorthand way that you might encounter.
All right, let's take a break and I'll see in the next one.