# 1.3 Variables - IP

Video Activity
Join over 3 million cybersecurity professionals advancing their career
or

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