Okey-Dokey.
Now we can actually start getting into learning Python properly.
So a little while ago what we did, we had this thing called
a 'print' statement or a 'print' function,
and we said, "Hello World", hit 'Shift + Enter',
and it says "Hello World".
And that is essentially all it takes to run a Python program.
But there are these things called variables.
And what I'm going to do is just delete that.
And a variable is really just a way to assign some sort of
'name' to have some sort of value.
So let's not do 'name',
let's do 'course', that's a variable name, is equal to, '=', and
we see just one equal sign.
Maybe I can make that a bit bigger here.
'course =',
and then we have different variable types, data types,
but we're going to keep this simple for now.
So let's use a quotation,
so we've an opening and closing quotation mark there. Not
"Course", let's do "Python for Everybody".
Hit 'Shift + Enter',
and it looks like nothing happened.
But if we type 'course', and then do 'Shift + Enter', our interactive
shell here will tell us that it is a value of "Python for
Everybody". And now what you can do is 'print()', your course name,
"Python for Everybody".
Now, the difference here is 'print' will actually print this
out, whereas just because we're in an interactive shell here,
this is sort of displaying it for us. In terms of which one you should use,
currently, when you're using Jupyter Notebook you can use either one,
it doesn't really matter.
But in a Python program, when you're actually creating a
'.py' file, you'll want to use the 'print' statement because
that will actually display text in your terminal, or in your
command line program.
So what I would like you to do is create a new Jupyter Notebook,
or open up your Python shell on your command line,
type in 'course = "Python for Everybody", and then
type in 'course', and then 'print(course), and that's it.
At that point in time, you have already assigned a variable.
Now, the nice thing about a variable is you can reassign
it. So we can say initially, 'course = "Python for
Everybody"'. But we could also say if we wanted to change that
value, we could say the course is now going to, for some
reason, transform into "JavaScript for Everybody",
and if I hit 'course', 'Enter', 'print(course)', 'Shift + Enter',
you can actually see if I scroll up here
'course' was originally "Python for Everybody". We printed it.
We know that that's exactly what it is.
And then we changed it to "JavaScript for Everybody".
Printed that.
And we now know that 'course' is now "JavaScript for Everybody".
So anytime we access it down the road, it's always going
to be "JavaScript for Everybody".
So we set the value "Python for Everybody", and then we overwrote it.
Now, that's basically how variables work.
It's just a name that points to something.
And that's actually the key behind a variable.
What a lot of courses won't tell you is how a variable works behind the scenes.
So a variable is just a name.
Python behind the scenes does not care what this is called.
It could be called literally anything.
There are some rules.
It should not start with a number, for instance. Should not
start with special characters.
Just give it a normal name with just regular letters and
maybe underscores,
and if you want uppercase letters.
So something like that. As long as it's just a regular text
name, Python doesn't care what it's called.
Then we use an equal sign.
And what this says is, "Hey, Python, please give me a little
piece of memory from the computer.
So a little piece of that RAM that's going on or some processing
power, however, memory is allocated on the particular computer,
I just need, let's say, 128 bytes of memory.
And wherever that is, I don't really care where it is
just give me 128 bytes of memory.
And then I'm just going to use a code name 'course' to
access those 128 bytes of memory".
Now, at this point in time, that 128 bytes of memory inside
of it says, "Python for Everybody".
And so really, what we're doing, is we're taking this text,
and we're jamming it into some sort of memory inside of your
computer. And so when the script runs, Python says, "Okay,
there's a name called 'course'.
I know that's sort of a code name for this piece of memory
that's, I don't know, way over here, and the user never needs
to know about it. But I know that it has a code name, of 'course'.
And inside of it, it says "Python for Everybody".
So whenever the user types 'course', I know that it's supposed
to be "Python for Everybody"."
So really, all it is, is you've got let's say a code name,
aka a variable name, is equal to,
and this will actually assign a piece of memory to this variable
for you, and then, "Anything you want in here".
And I'm actually going to undo that because I don't need
that. But then let's say down the road, I overwrite that
variable, which we did.
Now Python is going to say, "Okay, well, this has the same variable name.
It's already allocated to "Python for Everybody".
But what do I do about it?
I mean, it already has some data here.
So what do I do?"
And behind the scenes, Python is going to say, "This already
exists. You know what.
Throw it out. Delete it. Get rid of it.
Get out of here.
And I'm going to create a new variable with code name, of
'course'." So it's just going to be the exact same code name,
but is going to point to a different memory location.
That's how a variable works behind the scenes.
Now, that's a little important to understand
down the road, you don't need to know about it too much right
now. But just tuck that in your back pocket, because we're
going to reference this a little bit later in this course.
For now, setting a variable is super easy.
You say the variable name is equal to, and then whatever
the value is going to be. Make sure you have quotations in there,
because that is a particular data type that allows you
to use spaces and characters like P-Y-T-H-O-N.
So go ahead, give this a shot, create a variable, and then
print that variable out.
Once you have done that, I think we are ready to move on
to the next lesson.