Man: 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, the int 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.
Well, we can do that with variables.
So that in Python all we need to do is
name it whatever we want.
In our case, it'll be "IQ."
And we're gonna say, "IQ equals 190."
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 190 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,
oh, 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 190.
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.
And assigning a value,
is also known as binding.
That is we're binding the value 190 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 in memory."
And it's going to go look for that.
And because it's being bound to a value
it points to this value 190.
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 wanna be able to retrieve it.
And then when we print it to do, well get 190.
Now, we're gonna 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_case means it's all lower case, and then spaces,
while they don't exist, we use underscores.
Variables must start with a lowercase or an underscore.
Variables can be anything with letters,
numbers, and underscores.
But remember, they have to start
with lowercase and underscore.
That means we can't start a variable with a number.
They're also case sensitive.
That means if I create a variable,
but let's say this snake_case,
this variable, has a capital E instead of a lowercase E,
that'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 wanna 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 gimme an error
because I've changed the 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 we'll 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, well, it doesn't exist.
Again, it's case sensitive.
We have to make sure that we match.
And finally, we don't wanna overwrite keywords.
What does that mean?
Keywords in Python?
Well, they already mean something in Python.
For example, this print is a keyword.
You can see it highlighted in blue.
So that if I create a variable
saying print equals 190,
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 means something.
Now I know what you're wondering.
What are these keywords in Python?
That's a simple Google search away,
and we'll learn these throughout our course.
If we go to Python keywords by W3Schools,
you'll see that we have these keywords
that each means 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 keyword
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 keywords, there are different things
like for example, the i.n.t,
for integer that we've learned.
So these we're gonna 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 190,
and then I decide to, perhaps, have another variable,
call it "user age."
And for some reason I wanna assign
user age to perhaps have
IQ divided by four.
Is that going to work?
It should, right?
I'm saying user age is going to equal 47.5.
I'm using IQ, which is 190,
dividing it by four,
and then assigning it to user age.
I can maybe assign this to another variable
called "user age or called a",
and once again, I 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 gonna learn about classes
and classes actually have a different convention than this
but we'll get to that later on.
For now though, I wanna 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 3.14,
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 3.14 in memory
but then we overwrote 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 gonna 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 dunder.
And as you can see here, we have some
dunder 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 "hihi" and assign it a value.
I mean, you still can, however,
this is generally not good practice
so you wanna 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 gonna learn how to
name things well, so that our code reads like English.
And that's the whole point of writing good code.
The point of writing good code is that
it's readable and understandable by other programmers.
By the way, to finish off,
I just wanna show you one quick trick.
There's also a way that you might see, in some code bases
that uses something like this.
Equals 1, 2, 3.
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 1, 2, 3.
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.