‫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 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 you want.
‫In our case, it will be IQ and we're going to 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 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 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 want to be able to retrieve it.
‫And then when we print it to do well, get 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 lowercase and then spaces well 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 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, they'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 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 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 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 mean 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 three schools, you'll see that we have these keywords 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 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 int for integer
‫that we've learned.
‫So these 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 190 and then I decide to perhaps have another variable,
‫call it user.
‫Age.
‫And for some reason I want to assign user H 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 H or called A and once again.
‫I.
‫Run this and its 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 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.1 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 that 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 underscore 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 this 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.
‫High.
‫And assign it 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 and 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.
‫Equals 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 you in the next one.