Detailed Notes
This episode looks into literal types and order of precedence. 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/
Transcript Text
[Music] well hello and welcome back today we are going to talk about as we work our way through our django certification we are going to talk about data types particularly numeric types and those are going to be things like integers and floats and scientific notation and good stuff like that now going back to our interpreter we can play around a little bit so if we do x equals 3 we can also do y equals 3.4 so three we get an integer no we can do a uh three point four we can do uh z equals true and uh let's go to a equals um to and we're gonna do it uh scientific notation uh which is our other type which is a um uh here we go so scientific notation make sure i get it right i don't use it very often so it's an exponent oh so if i do that to the like uh ninth power and sure we'll do that i could do to the negative uh well let's do that so a equals that and b equals 3.14 did i get that right i think i did that wrong but that's okay so to the negative nine and that one is actually to the ninth i'm sorry so a little bit of typo there so if i print a so you know this is um scientific notation is just basically this means times 10 to the ninth so it's basically adding nine decimals uh pushing it over to the right adding nine decimals to it so we get this huge number uh if we use the smaller one where it goes the other way so negatives go to the left positives go to the right we're going to see that this is oh and it's actually going to print it out it's not going to do the 000. i think if we do a equals like negative 4 let's see what it does there yeah so it's there's a certain point where it's going to actually go to scientific notation because it's just a pain but if we look for if we do x y and z we can see and note that true and false are capital t or capital f and we can actually do type so we can see what these are so if i do type of a that's a float even though oh yes because it is scientific notation b is also going to be a float uh c if i do x that's going to be an int because it's going to take the one that makes the most sense y it's going to be a float because it has that decimal and then if we do z we're going to see if that is a boolean and we can add these together so if we do uh let's do type of a plus b which is going to be i'm going back here i'm sorry not a plus b let's do x plus y x plus y which is going to be 3 plus 3.4 6.4 and it's going to be a float because it's going to convert it out to what it needs to if i were to add to do two integers so like i can also convert so if i do that now it's going to be an nth and if i do because it's adding those two ends and now we're going to see that it converted it to that 3.4 i converted it just to 3 and gets us an end and so really the things you probably want to do is note that remember how to do x the scientific notation uh the rest of it you probably are good with but note that for example booleans are case sensitive and uh i'm you can find some stuff like numbers in python uh this little link to find just how to get stuff together there are some complex things that are out there um so if i were to do a equals 5x oh it doesn't like that uh oh because it's got to be a string and then it's going to be uh actually it's going to be a string so that's interesting it doesn't like that so if i do type of 5x it doesn't like that oh because it's got to be j i bet there we go if you want to do a complex number then you got to use j in there uh but basically obviously you can use imaginary or j to make it one so it can actually be so if i do a 5j done like that it does have to have it yeah so it doesn't like that but you can play around with your complex numbers i'm not sure how often you're going to deal with those but again it's just really because it does show up on our uh our types and of course uh strings so you can either slap double quotes or single quotes and you're going to be a string note that because you probably will see this something like this on the test so if i do a equals 1 b equals 2 and then i do print well let's just do a plus yeah let's do print a plus b it's going to be 3. but if i do uh a equals a string of one and b equals the string two and then i do print a print a there we go print a plus b note it combine it concatenates those strings i can't do minus on string so that's at least going to tell me i have to do that it doesn't support minus for strings whereas before if i go back to a equals 1 and b equals 2 and their numbers now it's going to be negative 1. and if i i'm going to have an issue so let's say i do a equals 1 b equals the string 2 and then i print a plus b in that case we're going to see here that's going to tell us hey one's a string and one's an integer that i don't support that that doesn't work so you're going to have to cast those out and we have seen that in some of the code we've used in the past so i just wanted to make sure i you know brought that forward that those are some of the types that we're working with now another one that you're going to run into i'm not going to go through the whole list but generally speaking is operator precedence so you're going to see things like if you are given i'm going to jump over here real quick so there's going to be things like if i do x equals 1 plus 3 times 5 minus 6 divided by 3 plus 9 times 6 that's in parentheses they may say okay well what is x equal to and this is going to do basic uh what i think is sort of standard precedence so you start with parentheses and so which that would be uh 9 times 6 is 54. so let's we'll back this up a little bit um we're going to simplify this sort of as we go so you start with the parentheses and then you work your way into brackets which makes sense because if you had like an array um so let's say y equals uh there's some sort of array one comma two comma three and you wanted to get the item in uh the first index or uh it could be the you know three minus two index you wanna you have to make sure that obviously you evaluate that to get to that index so brackets are going to take precedence precedence if you get in here i don't know that's going to run into it more more often you're going to see something like this so then we do left to right and we do uh multiplication and division so we're going to see here so we got our 54 but then we've got so we do one plus uh and so it's gonna be three times five is first so it's gonna do 15. and then there's a minus 6 divided by 3 and then there's a plus so we get this and then we just go left to right so we're going to do 16 minus 2 plus 54 16 minus 2 is 14 plus 54 and so that's going to get us to 68 and if i do this up and this way you can play around with it in the interpreter there we go so it's 68 and note that i get this which is a sort of good thing to note at times because i did this division it turns it into a float if i didn't have that so let's say i take that same thing and i just do instead of 6 divided by 3 i'm just going to make that let's just say i'm going to just switch it over so it's going to be 1 plus 1 so that i don't have well let's just do 1 times 2. so now because i didn't have any division in there and these are all integers then it's going to be an integer but if a division is automatically going to push it into a float so some of those kinds of automatic conversions are very good to know and then note that you're going to get down into this is going to be pretty important also as you get into we're going to talk probably a little later we actually definitely are going to talk a little later about some of our uh positives and negatives uh and bitwise kinds of shifts and ands and ores which becomes its own little thing uh is good to know probably not getting a lot get a lot of questions on that directly uh we will have a couple on bitwise shifts i think and ands and ors uh we will also get obviously go very heavily into boolean uh ands and knots and ores so we will talk about that as we go further along uh i will throw this link out in the notes because it's just a good one to look at or you can you could probably google or your favorite search engine python operator precedence and you're going to be able to see those there that being said i think it's a good time to wrap this one up so we will get out there and get to it you guys go out have a great day great week and we will talk to you next time you
Transcript Segments
[Music]
well hello and welcome back
today we are going to talk about
as we work our way through our django
certification
we are going to talk about data types
particularly numeric types
and those are going to be things like
integers and floats and scientific
notation and
good stuff like that now going back to
our interpreter we can play around a
little bit
so if we do x equals 3
we can also do y equals 3.4 so three we
get an integer
no we can do a uh three point four we
can do
uh z equals true
and uh let's go to a equals
um to
and we're gonna do it uh scientific
notation
uh which is our other type which is a
um uh here we go
so scientific notation make sure i get
it right i don't use it very often so
it's an exponent oh
so if i do that to the like
uh ninth power and sure we'll do that i
could do to the negative
uh well let's do that so a equals that
and b
equals 3.14
did i get that right
i think i did that wrong but that's okay
so to the negative nine and that one is
actually to the ninth
i'm sorry so a little bit of typo there
so if i print a so you know this is um
scientific notation is just basically
this means times 10 to the ninth so it's
basically adding
nine decimals uh pushing it over to the
right adding
nine decimals to it so we get this huge
number uh if we use the smaller one
where
it goes the other way so negatives go to
the left positives go to the right
we're going to see that this is oh and
it's actually going to print it out it's
not going to do the
000. i think if we do
a equals like negative 4 let's see what
it does there
yeah so it's there's a certain point
where it's going to actually go to
scientific notation because
it's just a pain but if we look
for if we do x
y and z
we can see and note that true and false
are capital t or capital f
and we can actually do type so we can
see what these are so if i do type of a
that's a float even though oh
yes because it is scientific notation b
is also going to be a float
uh c if i do x that's going to be an int
because it's going to take the one that
makes the most sense
y it's going to be a float because it
has that decimal
and then if we do z we're going to see
if that is a boolean
and we can add these together so if we
do uh let's do
type of a plus b which is going to be
i'm going back here i'm sorry not a plus
b let's do x plus y
x plus y which is going to be 3
plus 3.4 6.4 and it's going to be a
float
because it's going to convert it out to
what it needs to
if i were to add to do two integers
so like i can also convert so if i do
that
now it's going to be an nth and if i do
because it's adding those two ends and
now we're going to see that it converted
it
to that 3.4 i converted it just to 3
and gets us an end and so really the
things you probably want to do is note
that
remember how to do x the scientific
notation
uh the rest of it you probably are good
with but note that for example booleans
are
case sensitive and
uh i'm you can find some stuff like
numbers in python
uh this little link to find just how to
get stuff together there are some
complex things that are out there
um so if i were to do
a equals 5x
oh it doesn't like that
uh oh because it's got to be a string
and then it's going to be
uh actually it's going to be a string so
that's interesting it doesn't like that
so if i do
type of 5x
it doesn't like that oh because it's got
to be j
i bet there we go
if you want to do a complex number
then you got to use j in there
uh but basically obviously you can use
imaginary
or j to make it one so it can actually
be
so if i do a 5j
done like that it does have to have it
yeah so it doesn't like that but you can
play around with your complex numbers
i'm not sure how often you're going to
deal with those
but again it's just really because it
does show up
on our uh our types
and of course uh strings
so you can either slap double quotes
or single quotes and you're going to be
a string note
that because you probably will see this
something like this on the test so if i
do a
equals 1 b equals
2 and then i do print well let's just do
a plus
yeah let's do print
a plus b
it's going to be 3. but
if i do uh a equals a string of one
and b equals the string two and then
i do print a print a there we go print
a plus b note it combine it concatenates
those strings
i can't do minus on string so that's at
least going to tell me i have to do
that it doesn't support minus for
strings whereas
before if i go back to a equals 1
and b equals 2 and their numbers
now it's going to be negative 1.
and if i i'm going to have an issue so
let's say i do a equals 1
b equals the string 2 and then
i print a plus b
in that case we're going to see here
that's going to tell us hey one's a
string and one's an integer that i don't
support that
that doesn't work so you're going to
have to cast those out and we have seen
that in some of the code we've used in
the past
so i just wanted to make sure i you know
brought that forward that those are some
of the types that we're working with
now another one that you're going to run
into i'm not going to go through the
whole list
but generally speaking is operator
precedence so you're going to see
things like if you are given i'm going
to jump over here real quick
so there's going to be things like if i
do x
equals 1 plus 3
times 5 minus 6
divided by 3
plus 9 times 6 that's in parentheses
they may say okay well what is x equal
to
and this is going to do basic uh what i
think is sort of standard precedence
so you start with parentheses and so
which that would be uh 9 times 6 is 54.
so let's
we'll back this up a little bit um we're
going to simplify this sort of as we go
so you start with the parentheses and
then you work your way into brackets
which makes sense because if you had
like
an array um so let's say y
equals uh there's some sort of array one
comma two comma three
and you wanted to get the item in
uh the first index or uh it could be the
you know three minus two index you wanna
you have to make sure that
obviously you evaluate that to get to
that
index so brackets are going to take
precedence
precedence if you get in here i don't
know that's going to run into it more
more often you're going to see something
like this so
then we do left to right and we do uh
multiplication and division
so we're going to see here so we got our
54 but then we've got
so we do one plus
uh and so it's gonna be three times five
is first so it's gonna do 15.
and then there's a minus 6 divided by 3
and then there's a plus so we get this
and then we just go left to right so
we're going to do
16 minus 2 plus 54
16 minus 2 is 14 plus
54 and so that's going to get us to 68
and if i do this up
and this way you can play around with it
in the interpreter
there we go so it's 68 and note
that i get this which is a sort of good
thing to note at times
because i did this division it turns it
into
a float if i didn't have that so let's
say
i take that same thing and i just do
instead of 6 divided by 3
i'm just going to make that
let's just say i'm going to just switch
it over so it's going to be 1 plus 1 so
that i don't have
well let's just do 1 times 2.
so now because i didn't have any
division in there and these are all
integers then it's going to be an
integer but if
a division is automatically going to
push it into a float
so some of those kinds of automatic
conversions
are very good to know and then
note that you're going to get down into
this is going to be pretty important
also as you get into we're going to talk
probably a little later we actually
definitely are going to talk a little
later
about some of our uh positives and
negatives
uh and bitwise kinds of shifts and ands
and ores which
becomes its own little thing uh is good
to know
probably not getting a lot get a lot of
questions on that
directly uh we will have a couple on
bitwise shifts i think and ands and ors
uh we will also get obviously go very
heavily into boolean
uh ands and knots and ores so we will
talk about that
as we go further along uh i will throw
this link out in the notes
because it's just a good one to look at
or you can you could probably google or
your favorite search engine python
operator precedence and you're going to
be able to see those there
that being said i think it's a good time
to wrap this one up
so we will get out there and get to it
you guys go out have a great day
great week and we will talk to you next
time
you