>> Hello, everyone, and welcome back to intro
to Python here on Cybrary OnDemand.
I as always, I'm your instructor
Joe Perry, and as always,
I'm very excited to be here today
to talk to you about programming basics.
Today we're going to be focusing on variables,
because we are in lesson 2.
The objectives in this lesson.
We're going to talk about the concept of variables,
what they are, what they're for, what they do.
We're going to learn about
the different generic variable types.
Now this is a very broad
description of the variable types.
There are a lot of sub-types of these,
there are a lot of people who will disagree
about what a generic variable even means.
But for the course of this video,
because I'm the one making the recording,
I get to decide what is and is not going to be covered.
I'm going to say there are numbers,
there are strings, and there are structures.
Variables. What are they?
What are they for? What do they do?
The best way to describe variables
is tupperware for your brain.
Variables can be really tricky for new people to learn.
A lot of people get very
wrapped around the axle with the concept of them,
and the truth is that they're not
nearly as complicated as they seem.
They're not nearly as complicated as you may
unintentionally make them seem.
In reality, variables in
programming work exactly the same way as they do in math.
In math, you have a variable that
represents an unknown value.
When you're searching for x, all you're trying to
do is figure out what that unknown value is.
But the point stands, that it's there to
represent that value, whatever it may be.
In programming, it's exactly the same.
Your variables exist,
oftentimes we use x as a variable.
Your variables just exist
to represent unknown information.
Sometimes that information is
going to be put by the user.
Sometimes it's derived from some other operation.
The key thing to understand is that
the variable in these equations
here where we have two plus x and four plus x,
the variable is just a stand-in for
information that we have not yet determined.
Tupperware for your brain.
What's in a name? This is
a slightly tongue-in-cheek reference.
If you've not seen the image right above me,
that is from the 1996 Romeo and Juliet adaptation.
Wow, is it a bad movie?
It's one of the most unintentionally
funny movies of all time.
That's not relevant to programming.
I like to remind people that it exists,
and that it does involve Romeo and Juliet set in Malibu,
but with the exact same language.
They still speak in Shakespeare in English,
but also they drive convertibles.
I'm just going to let that sink in for a second.
Moving on back to programming.
Depending on the language in the paradigm,
like I said, there are a lot of
different kinds of variables,
and different people will disagree
about what constitutes each type of
variable and whether or not you can
even have a generic variable.
What's important to understand here
is that all we're really trying to
describe are bins for the types of variables.
We're going to discuss Pythons in a few lessons.
We're going to spend
very long times in each of the Module 2 lessons,
deep diving the different types of Python variable.
But for now we're just going to use the
broad terms of numbers,
string, and structure.
Numbers. A number is
a single number in the real number set.
Complex numbers can be represented in programming.
Generally speaking, there are special modules
and libraries do that for you,
or to help you do it.
Generally speaking, you're going to be
working in real numbers and programming unless
you're working in physics or in mathematics or whatever.
When you're writing a program,
you're going to deal with real numbers most of the time.
Zero, 1, 2, 3, 4, 5,
onward to infinity at infinitum, 0.1,
0.01, 0.001, 0.0001,
etc., things like Pi or e or the natural log,
all of those are real numbers.
All of those are relatively easy to
represent with programming variables.
Strings, which are actually a derivation of numbers.
In programming, we've talked about in our last video,
all of computer science is derived from zero and one.
Therefore, strings really are
just representations to the screen,
to the user, to the program,
of zeros and ones.
That said, strings are their own type of
variables because they do operate
differently from numbers.
They generally exist to hold
one or more printable characters.
It's possible to use
non-printable characters and strings.
You'll see that used a lot in pen testing
and in exploit development.
But generally speaking, a string will
hold one or more printable characters.
Here we see uppercase,
a lowercase, a punctuation,
weird marks or sentences,
entire arrays of character. Finally, structures.
Now structures is a very broad description.
All it really means is
some abstract datatype derived from numbers and strings.
Really, what that means is derived from numbers.
Structures can be used to represent all sorts of things.
There are structures out there that will
represent entire web servers.
There are structures, as you can see,
over the side have a blueprint.
There are structures that are blueprints
for code or blueprints for buildings.
A structure, again, is just an abstract data type
that represents something that's more complex,
that needs more operational capability than
just numbers. Knowledge check.
I left these on the screen because I really want to just
dig into it rather than doing a quiz.
But which datatype is x
in each of the following statements?
X equals test is a string,
because, and this is very important,
this is one of the reasons why I didn't make this a quiz,
instead made it a check,
strings are almost always going to be enclosed in quotes.
In Python, which is the class you're taking,
strings are always enclosed in quotes.
They might be a single quote,
they might be a double quote,
they might be a set of three double quotes
and single quotes on either side,
and we'll talk about what that's for in a while,
but they will be enclosed in quotes.
That's how you know it's a string.
One of the main gotchas, if you look down to
the third item here where x equals object one,
that's a structure because there aren't quotes.
Python will interpret that as a variable,
not as a string.
A lot of times when you're writing Python code,
people will forget their quotes
and their program will break,
and they won't understand why
and they'll come to me, Joe,
I don't know what's happening, what's wrong
with my code, can you fix it?
I put in a pair of quotes and
then they have to walk away shame-faced.
That's one of the first things you want to check.
We're going to talk about
gotchas as we go through this course.
There are a lot of specific problems
that crop up over and over again in programming,
and that's one of the big ones.
Of course, x equals 1.2, in that case,
x is a number variable.
Summary, what did we cover in this video?
Well, what are variables?
The answer to that question is tupperware for your brain.
Then we broadly talked about what
types of variables exist,
numbers, strings, and structures.
That's really all there is for this video.
I hope to see you back at our next one which is going to
be programming basics if statements.
We're going to start in on flow control,
and that may not seem exciting,
but it really is because
that's one of the first steps you have to take
to writing true functional, real programs.
I hope to see you back. As always,
I've been your instructor, Joe Perry,
and you were watching this on Cybrary OnDemand.