Detailed Notes
This episode looks into bitwise operators. More to come on this in the next episode.
Helpful links: https://overiq.com/python-101/numbers-in-python/ https://www.mathcs.emory.edu/~valerie/courses/fall10/155/resources/op_precedence.html
Learn more about the overall certification and syllabus here: https://pythoninstitute.org/certification/pcap-certification-associate/pcap-exam-syllabus/
Github repository for code examples: https://github.com/robbroadhead/PythonCertificationSeries
Transcript Text
[Music] well hello and welcome back we are continuing looking through the java certification uh series i'm not sorry java python certification series and today we're going to look at numerical operators we'll probably actually get into bitwise as well there will be a link in the show notes for the github uh there's gonna be a public github repository floating out there i'm gonna throw these examples uh at this point we were just working in the interpreter and just sort of typing some code although i did uh include you'll see app one uh if it'll pop up that we sort of played around with last time this time we're gonna go through and we probably will go through this first part pretty quick and then jump into uh operators for bitwise operators i'm going to do my best to name files based on essentially the main issue there for each of these bullet points so that hopefully we'll be able to find those moderately quickly when you're doing some research or studying for an exam as far as operator is concerned we'll start with operators and then what type they are so for example operators numeric is we're going to go here so let's start with these and we're going to start with and actually we'll just do it like this is we will do an example of and we start with the simple ones so we're going to start with whoop and so we're going to go with you know the basics and we should be able to see i'm hoping everybody knows these plus minus times and divide and then whoop and then we're going to come down and we're going to do a couple that may not know as much which is going to be double that double that and percent and so plus is simply going to be we'll do this way um we will do and these are for um let's do this we're going to do this just to be sure because we are going to come back around and we're going to actually have some um we're going to have some like strings and other examples there we go okay so example plus so let's do a 1 plus 2 plus plus 3 and then we're just going to do the same thing and then we're going to do minus let's do 10 minus four minus two actually let's do this minus eight just to do something a little different because i wanna make sure we see that minus four minus eight i'm multiples let's pull this here let's do this is gonna be uh we'll do something simple so we'll do two times three times one that's one and then division we'll do um let's do 100 divided by 5 divided by 40. and then we will walk through each of these as we do it so let's go with that first and if we flip over here and we do python three operators that so here's what we see is uh so plus pretty straightforward one plus two is three three plus three is six if we do minus notice here ten minus four is six six minus eight is actually negative two i'm going to play around with that with a second and then an example of multiplications two times three is six six times one is six now let's flip back over here and let's change that to a negative one so now because we're binding this here since it's right next to it that's going to be a negative one so there is a difference here also of if we do a positive three let's look at these two and so we'll see here if you put it right next to it if you don't have that space then it's a positive three uh we did the negative here we go that's a negative one so now it's two times three times negative one is minus 6. if we break that out uh here it's going to think it's an operator oh i'm sorry if we do that and we're going to probably see a nice little error oh it still took it there okay we got lucky because it it was smart enough to figure that out normally you want to do it there because it is for readability's sake so it's important to remember that you can do that if you were to do um other sometimes i'll get a little confused we'll show that in a minute oh let's do the division real quick uh so division 100 divided by 5 we get a 20 and 20 divided by 40 is a half so notice it flips over to a decimal or a float and then if we take this and then we do that whole thing we get the whole thing done and then come back here and do plus two then we're going to see that it's going to still be a decimal and if we do it times plus 1.5 so that it would be an integer notice it's still a float it's still keeping that any questions of course not because you're listening you're not this is interactive but this is pretty straightforward for the most part just remember things like negatives and positive numbers those would probably be the only things that may trip you and really they're not it's going to be more order precedence these next guys are a little bit less common so let's do each of these so if we do let's just do this let's do uh two times three let's do uh three divided by two actually let's do like uh 17 divided by four and then here let's do seventeen percent four and we'll look at each of these let's get rid of our quotes and let's walk through these a little bit so if we look at this these second series so the first one we've got is 2 times 3 multiple times or asterix 3 that is power that is 2 to the third power so it's actually the same as in this case it's going to be the same as two times two times two let's get all my space there so if we do like let's say three to the fourth power that's also gonna be three times 3 times 3 times 3. so if you look at that there you go so 2 to 3 is 8 3 to the fourth is 91. so it's 3 to the 4th is 3 times 3 which is 9 times 3 is 27 times 3 is 81. so we do the um the double division this is difference between a div and a mod and what it is between those two sometimes you some people haven't run into this as much is the difference between in a division whether you're dealing with the uh the number of times it goes in or the you know the remainder because with the regular division we saw here and actually let's do that with this 17 and four let's just do one other so we can do this a little bit so what you're going to see here is if you do a single divisor a single divide it's going to give you the decimal if you do the double it's going to take it and do a div which is basically how many what is this number how many times complete times does it go into uh does this the divisor go into the divider i forget which is which but the the guy at the top how much does the how often does the guy on the bottom the denominator go into the guy at the top 4 goes into 17 four times we see here 4.25 so we'll get that if you do a percent it's going to give you the remainder so 4 goes into 17 four times which leaves you 16 and then you have a remainder of 1. so these don't show up as often but they do so i think they're pretty important for us to to remember those and again you can always check them out if you need to but uh it's useful to let me do this guy uh it is useful to uh duplicate this sorry i'll go through this i'm gonna duplicate this so this is gonna be uh binary i'm sorry that was bitwise i'll call it bitwise uh so it's good to remember those things as you get into it because sometimes you'll forget those things you'll get in and you'll sort of freak out a little bit so this is i'm sorry bit wise the bitwise is a little more complicated because here we're actually dealing with the uh bit version of the numbers or the strings so first let's just do a tilde and so let's do uh let's do four tilde uh one i don't know if i can get that number there and we're going to take these a little more slowly oops the reason we have this is because this is not a uh an a operator b kind of thing this is actually a bit flipper and so um let's see so it helps to know what numbers look like so in bit format [Music] and so if this is zero in bets then you add this and that's going to be one that's two that's three that's four so if we do uh let's see four in bits and what this is going to do is it's going to flip it so we're going to end up and let's just do flip 2 so it's going to be 1 0 1 1 so that means 0 becomes a one one becomes a zero which is actually so that's your ones your twos your fours and your eights so that's gonna be eight plus two plus one which is eleven so if we print that well we're going to get this and actually because of its size uh it's going to be a negative 5 because we're actually seeing this as a negative um and we're going we're wrapping around in this case let me try something a little bit play around with that though a little bit now oops now one is we're gonna see that if we do a number and let's take uh let's do something different let's do five so five and bits is this guy and that means that we're going to flip them he's going to be 101.0 and then watch what happens so if we do um a equals 25 and then we do print until the a we're gonna get back five so let's see where'd we go here i've gotta find my thing so we see here we go we come in we flip four he becomes a negative five we could flip five that's a negative six now i want to make it a little clearer because it can get pretty complicated as far as when negatives show up and when they don't let's just look at what we can do is we can format these guys and so if we format that [Music] so let's do it like this let's do it before and after and we'll see this a little bit when we get into strings later but i think this will work for now so let's take a look at this did i say that i did and so here you can see where it's actually it's flipping it you can see it's actually converting it over to a number and so it takes that 101 to 1001 and it's flipping it around because it's doing a wrap around on it and then uh where'd we go oh so that's yeah so here's the four and then five is going to flip those over and of course we can always come back to it this is useful in some areas basically when we're trying to do like and um some logical stuff but uh it's a start on the bitwise stuff and like i said i'm not sure how often you're gonna need it other than when you're setting flags for example um and if you get into some deeper kinds of uh coding but it's important to know that at this point uh that the little tilde reverses it and let's just do that let's see flip bits we'll call that now the ampersand let's get over to that and let's do this one um well i'm not gonna i'm gonna have to we'll have to explain so what this does is this is a bit wise and which means uh let's look at our numbers before so if we looked at um yeah i'm not gonna be able to do it this way i'm not gonna be able to show you the initial as much so if i do like a four and a five when you look at those [Music] let's go pick up these two so four in bits is this five is zero one zero one and this actually the reason we're seeing these negatives is actually it's treated as something like this and so you get something that's a little bit funky but what an and does is it takes everything where there's a one and turns it into one so the and turns this into one two three four five there's a one and one and a one so that should be a seven so if we do that so the last three we're going to see there because it's not flipping it's just doing ands and so if we were to print without the format [Music] see oops i don't need the format get rid of that then what we're going to see here on our ampersand is not going to tell me what i want it to i'm sorry and is it's got to be both i'm sorry shoot it's an and not an or i talked about that in a minute so the or is it's one or the other has to be so it actually ends up being this because zero or zero is zero zero zero zero zero and then we go one or one is one zero or one is one i'm sorry zero or zero is one and then zero or one is one so if we were to take something more complicated um let's do like a i don't know like a 17 i have no idea what that is we're going to figure that one out real quick uh so that's one two four eight so that's that's going to be like a 17 and let's do like a let's do a nine no it's like a 15. it's a 15 it's going to be i think one on one one one two four eight twelve and three is fifteen so that's going to end up being this guy so if we do 17 and 15 17 and 15. oh and it simplifies it back down to one on me because it's one or one plus one or one plus one or one plus one or one did that get right i'm sorry and oh geez and and why do i keep saying one or it's one and so one and is only going to be this last one that's the only and i'm so sorry um so zero and zero we get down here one and one is one zero and zero is zero zero and one is zero so that's the four right uh oh we didn't keep that one [Music] in order doesn't matter by the way so look if i do at least in the bitwise and because we're just doing an ant on each of the things it doesn't matter that you know which is which so we're gonna see that um four bits there oh i'm sorry yeah okay so that's a yeah four oh i'm sorry it's not 100 that's a that's a bit wise my mistake and then here since we're doing hands we get down to that one all right so i'm gonna hold off at this point on the next piece uh next we're going to come into is we're going to start taking a look into these other operators because i don't want to get too long on this one so we'll come back to part two working our way through our operators as always like i said it's going to be in the show notes where the the links to github are so you can see all the source and all these little notes along the way and as always you can also shoot an email out to info development.com or throw a comment out on the youtube channel if you've got any questions uh or want any clarifications on any of these pieces so until the next time have yourself a great day a great week and we'll talk to you then you
Transcript Segments
[Music]
well hello and welcome back
we are continuing looking through the
java certification
uh series i'm not sorry java python
certification series
and today we're going to look at
numerical
operators we'll probably actually get
into bitwise as well
there will be a link in the show notes
for the github uh there's gonna be a
public github
repository floating out there i'm gonna
throw these examples
uh at this point we were just working in
the interpreter and just sort of typing
some code
although i did uh include you'll see app
one
uh if it'll pop up that we sort of
played around with last time
this time we're gonna go through and we
probably will go through this first part
pretty quick and then
jump into uh operators for bitwise
operators i'm going to do my best to
name files based on
essentially the main issue there for
each of these bullet points so that
hopefully
we'll be able to find those moderately
quickly when you're doing some research
or studying for an exam as far as
operator is concerned we'll start with
operators
and then what type they are so for
example operators numeric is we're going
to go here
so let's start with these and we're
going to start with
and actually we'll just do it like this
is we will do
an example of
and we start with the simple ones so
we're going to start with
whoop
and so we're going to go with you know
the basics and we should be able to see
i'm hoping
everybody knows these plus minus
times and divide
and then whoop and then we're going to
come down
and we're going to do a couple that may
not know as much
which is going to be
double that double that
and percent and so plus
is simply going to be
we'll do this way um we will do
and these are for um
let's do this we're going to do this
just to be sure because we are going to
come back around and we're going to
actually have some
um
we're going to have some like strings
and other
examples there we go okay so example
plus
so let's do a 1 plus 2 plus
plus 3
and then we're just going to do the same
thing
and then we're going to do minus
let's do 10 minus
four minus two actually let's do this
minus
eight just to do something a little
different
because i wanna make sure we see that
minus four
minus eight i'm multiples
let's pull this here
let's do this is gonna be uh we'll do
something simple so we'll do
two times three times one
that's one and then division
we'll do um
let's do 100 divided by 5
divided by 40.
and then we will walk through each of
these as we do it
so let's go with that first
and if we flip over here
and we do python three operators that
so here's what we see is uh so plus
pretty straightforward one plus two is
three three plus three
is six if we do minus notice here ten
minus four is six
six minus eight is actually negative two
i'm going to play around with that with
a second
and then an example of multiplications
two times three is six six times one
is six now let's flip back over here
and let's change
that to a negative one so now because
we're binding this here
since it's right next to it that's going
to be a negative one
so there is a difference here also of
if we do a positive three let's look at
these two
and so we'll see here if you put it
right next to it if you don't have that
space
then it's a positive three uh we did the
negative here we go that's a negative
one so now
it's two times three times negative one
is minus 6. if we break that out uh
here it's going to think it's an
operator oh i'm sorry if we do that
and we're going to probably see a nice
little error
oh it still took it there okay we got
lucky because it it was smart enough to
figure that out normally you want to do
it there because it is for readability's
sake
so it's important to remember that you
can do that if you were to do
um other sometimes i'll get a little
confused we'll show that in a minute oh
let's do the division real quick
uh so division 100 divided by 5 we get a
20
and 20 divided by 40 is a half so notice
it flips over
to a decimal or
a float and then if we take this
and then we do that whole thing
we get the whole thing done
and then come back here and do plus two
then we're going to see that it's going
to still be a decimal
and if we do it times plus 1.5
so that it would be an integer notice
it's still a float
it's still keeping that any questions
of course not because you're listening
you're not this is interactive but
this is pretty straightforward for the
most part just remember
things like negatives and positive
numbers
those would probably be the only things
that may trip you and really they're not
it's going to be more order precedence
these next guys are a little bit less
common
so let's do each of these so
if we do let's just do this let's do uh
two times three
let's do uh three divided by two
actually let's do like uh
17 divided by four and then here let's
do
seventeen percent four
and we'll look at each of these
let's get rid of our quotes and let's
walk through these a little bit
so if we look at this these second
series so the first one we've got is 2
times 3 multiple times or asterix
3 that is power that is 2 to the third
power
so it's actually the same as in this
case
it's going to be the same as two times
two times two
let's get all my space there so if we do
like let's say three to the fourth power
that's also gonna be three times 3 times
3
times 3. so if you look at that
there you go so 2 to 3 is 8 3 to the
fourth
is 91. so it's 3 to the 4th is 3 times 3
which is 9 times 3 is 27 times 3
is 81. so we do the um
the double division this is difference
between a div
and a mod and what it is between those
two sometimes you
some people haven't run into this as
much is the difference between
in a division whether you're dealing
with the
uh the number of times it goes in or the
you know the remainder
because with the regular division we saw
here
and actually let's do that with this 17
and four let's just do one other
so we can do this a little bit so what
you're going to see
here is if you do a single divisor
a single divide it's going to give you
the decimal if you do the double
it's going to take it and do a div which
is basically
how many what is this number how many
times complete times does it go into uh
does this
the divisor go into the divider i forget
which is which
but the the guy at the top how much does
the how often does the guy on the bottom
the denominator go into the guy at the
top
4 goes into 17 four times we see here
4.25 so we'll get that
if you do a percent it's going to give
you the remainder so
4 goes into 17 four times which leaves
you 16
and then you have a remainder of 1. so
these don't show up as often
but they do so i think they're pretty
important for us to
to remember those and again you can
always check them out if you need to
but uh it's useful to
let me do this guy uh it is useful
to uh duplicate this sorry i'll go
through this i'm gonna duplicate this
so this is gonna be uh binary
i'm sorry that was bitwise i'll call it
bitwise
uh so it's good to remember those things
as you get into it because sometimes
you'll forget those things you'll get in
and you'll sort of freak out a little
bit
so this is i'm sorry bit wise
the bitwise is a little more complicated
because here
we're actually dealing with the uh
bit version of
the numbers or the strings so first
let's just do a tilde
and so let's do
uh let's do four
tilde uh one
i don't know if i can get that number
there
and we're going to take these a little
more slowly
oops
the reason we have this is because this
is not a uh
an a operator b kind of thing this is
actually
a bit flipper and so um
let's see so it helps to know what
numbers look like
so in bit format
[Music]
and so if this is zero in bets
then you add this and that's going to be
one
that's two that's three
that's four
so if we do uh let's see four in bits
and what this is going to do is it's
going to flip it so we're going to end
up
and let's just do flip
2 so it's going to be 1 0 1 1
so that means 0 becomes a one one
becomes a zero
which is actually so that's your ones
your twos
your fours and your eights so that's
gonna be eight plus two plus one which
is eleven
so if we print that well
we're going to get
this and actually because
of its size uh it's going to be a
negative
5 because we're actually seeing this as
a negative
um and we're going we're wrapping around
in this case let me try something
a little bit play around with that
though a little bit now oops
now one is we're gonna see that if we do
a number and let's take uh
let's do something different let's do
five so five
and bits is this guy
and that means that we're going to flip
them he's going to be 101.0
and then watch what happens so if we do
um a equals
25 and then we do print
until the a
we're gonna get back five so let's see
where'd we go here i've gotta find my
thing
so we see here we go we come in
we flip four he becomes a negative five
we could flip five
that's a negative six
now i want to make it a little clearer
because it can get pretty complicated as
far as when negatives show up and when
they don't
let's just look at what we can do is we
can
format these guys and so if we
format that
[Music]
so let's do it like this
let's do it before and after
and we'll see this a little bit when we
get into strings later but i think this
will work for now
so let's take a look at this did i say
that i did
and so here you can see where it's
actually it's flipping it you can see
it's actually converting it over to a
number
and so it takes that 101
to 1001
and it's flipping it around because it's
doing a wrap around on it and then uh
where'd we go oh so that's yeah so
here's the four
and then five is going to flip those
over
and of course we can always come back to
it
this is useful in some areas basically
when we're trying to do like and
um some logical stuff but uh it's a
start
on the bitwise stuff and like i said i'm
not sure how often you're gonna need it
other than when you're setting flags for
example
um and if you get into some deeper kinds
of uh coding but
it's important to know that at this
point
uh that the little tilde
reverses it and let's just do that let's
see
flip bits we'll call that
now the ampersand
let's get over to that
and let's do this
one um well i'm not gonna i'm gonna have
to we'll have to explain so what this
does
is this is a bit wise
and which means uh let's look at our
numbers before so if we looked
at um
yeah i'm not gonna be able to do it this
way i'm not gonna be able to show you
the initial as much so if i do like a
four
and a five
when you look at those
[Music]
let's go pick up these two so four in
bits
is this five
is zero one zero one
and this actually the reason we're
seeing these negatives is actually it's
treated as something like this
and so you get something that's a little
bit funky but what
an and does is it takes everything where
there's a one and turns it into one
so the and turns this
into one two three
four five there's a one and one and a
one
so that should be a seven so if we do
that
so the last three we're going to see
there because it's not flipping it's
just
doing ands and so if we were to print
without the format
[Music]
see oops i don't need the format get rid
of that
then what we're going to see here on our
ampersand
is not going to tell me what i want it
to
i'm sorry and is it's got to be both i'm
sorry shoot it's an
and not an or i talked about that in a
minute so the or
is it's one or the other has to be so
it actually ends up being this because
zero or zero is zero zero zero zero zero
and then we go one or one is one
zero or one is one
i'm sorry zero or zero is one and then
zero
or one is one so if we were to take
something more complicated
um let's do like a i don't know like a
17
i have no idea what that is we're going
to figure that one out real quick
uh so that's one two four eight
so that's that's going to be like a 17
and let's do like a
let's do a nine no
it's like a 15.
it's a 15 it's going to be i think one
on one
one one two four eight twelve and three
is fifteen
so that's going to end up being
this guy
so if we do 17 and 15
17 and 15.
oh and it simplifies it back down to one
on me
because it's one or one plus one or one
plus one or one plus one or one did that
get right
i'm sorry and oh geez and and why do i
keep saying one or it's
one and so one and is only going to be
this last one that's the only and i'm so
sorry
um so zero and zero
we get down here one and
one is one zero and zero is zero
zero and one is
zero so that's the four right
uh oh we didn't keep that one
[Music]
in order doesn't matter by the way so
look if i do
at least in the bitwise and because
we're just doing an ant on each of the
things it doesn't matter that
you know which is which so we're gonna
see that
um four bits there
oh i'm sorry yeah okay so that's a
yeah four oh i'm sorry it's not 100
that's a that's a bit wise my mistake
and then here since we're doing hands we
get down to that one
all right so i'm gonna hold off at this
point on the next
piece uh next we're going to come into
is we're going to start taking a look
into these other operators because
i don't want to get too long on this one
so we'll come back to part two
working our way through our operators as
always like i said it's going to be in
the show notes where the
the links to github are so you can see
all the source and all these little
notes along the way
and as always you can also shoot an
email out to info development.com or
throw a comment out on the youtube
channel if you've got any questions
uh or want any clarifications on any of
these pieces so
until the next time have yourself a
great day a great week
and we'll talk to you then
you