Detailed Notes
We start wrapping up with a review of some topics that need more discussion before taking the certification. This episode is focused on function attributes.
Useful Links: https://docs.python.org/3/reference/datamodel.html https://realpython.com/documenting-python-code/
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 our series of episodes on getting your python certification and we're getting really close to the end this may be the last one other than sort of like a summary and the thing that i want to swing back around to is when we did functions we touched on properties of a function and we did this with modules as well but i want to make sure that we go back through those because there are some questions on those that i found at least in the sample test and i think it's good to make sure you've touched on each of those and there's several so for this example um i just created this function called myfunk it's got a couple parameters it prints something and let me return something too just to be complete so there you go so it prints it it returns it so if i call my func two comma three then we'll see what happens so if i do that the first one i look at is under score underscore str so if we do uh python three extra is that what i call it there we go then we see that it just i called it it did a little print it returns it if i do it as a string then right now since i haven't defined it in any specific way then it's going to give me basically it's a you know the name and the um the memory address that exists at so string is not terribly interesting um generally speaking for functions that you can do let me give you a couple of these but another one we can do is we can do doc and let me do let me do this one at a time so let's do doc and there's nothing there uh here there's nothing there is no dock that's available and we haven't really talked about this but what i can do is i can come up here and mention that that prints a plus b oops b and returns it [Music] so now if i come through um oh it may be without that sorry it's a string so um the string is a function oh let's do this actually let's get more specifically so what we see here is some of these are some of these underscores are functions and some are attributes um you can see here um string is a function but i if i call it then it gives me this with the dock i can actually see comments and if i do this triple triple double quote then that is a built-in dock it is built-in comments for your your function your uh your method if you're dealing with the client your class so it's one of those things we haven't touched on when you talk about comments and documentation but that triple quote triple double quote which is itself sort of difficult allows you to do that kind of stuff it allows you to also then have it exposed you can come back later and do you know documentation related stuff through the dock so let's pick uh let's go here let's do another uh next one we'll do is let's go ahead and do code i think we have done code and it's a code is an object um i think i need to get let's see i don't know if that's gonna work let's try this real quick i think you could get it uh no it just gives me a code object so it doesn't give it in a i don't get in a string format but what i do get is i get this code object so i could actually when we talk about lambdas and think lambdas and things like that i could actually do stuff with that i can actually push stuff around and actually call things based on that again it's so that you can get all of the different you can actually dissect basically your functions uh annotations i didn't see anything on it but there are i haven't really gone into annotations too much but you can get that if you have those call is going to actually call it so instead of doing this way you could actually do it as a call which makes very little sense we've talked about class if we look at defaults that's one i'm pretty sure that's up there let's see so we did doc so we're seeing what we did oh now we did name oh let's do call name let's do that first well if we do defaults just because i was taking that in order there aren't any because i didn't do it but if i do a equals zero b equals zero then i can see what my default values are so i can see what the defaults are if i'm trying again if i'm trying to dynamically create stuff i can figure it out through there uh let's do call name oh we did string we didn't do names so if i do let's look at name and call name if we look at those two then it's going to be the same one um it depends it basically depends on whether or not you're within a module or something like that then you can see you can see things that get aliased out but if you want to actually get the name of the function so string is a string of the function the or underscore underscore str it's the function itself it's not you know the name so normally you're going to want to work with the name instead of the name or the call name uh the mod we've talked about module we see defaults code and note here this is the it's the compiled function body but you can also actually replace stuff on the fly um let's do globals and what we're going to see here if we jump to this one is uh starting here to here um these are all the different things we can call on it and we've seen this before with when we're looking at classes but you can see here that it's like some of the things we've seen we've got name a main a doc which is yeah none uh what package you're in uh loader the blah blah blah blah blah we talked about now supplications let's do spec and um so let's do let's pick up a couple of these let's go look at spec and let's look at let's see let's do file so if we look at those two uh it doesn't have a spec attribute um even though it is there it's because it's not oh there it is because it is none but i could write to it uh file file file and it's gonna show what file it's in so let's get that uh oh it doesn't have it um which is interesting even though it says here oh it's a global these are the globals available to it so i can take aldo so i can see uh it's not this if i do this then i get to see it so i'm sorry those are um these are all the globals that are available within that function uh so we've got uh dictionary is one that we uh let's go here dick which is my funk so oh so if we do the dictionary let's take a look at that guy so see here it doesn't have anything uh this is really not anything notable of it um where'd it go but it's basically for uh if i had an additional attribute within the function if i did let's try like name equals this function i think then we will see that it'll show up nope nope it doesn't because it's not oh because it's an attribute of the function that we we could add to we haven't so it would be more like my funk dot um [Music] equals custom value and i think now i'll see yep there we go so i can remember these things are all dynamic so i can actually add stuff i can slap all kinds of attributes onto things and so dictionary gives me that let's see closure be the last one of these whoop just do it this way and let's take a look at that after our little custom value and there isn't any because what you get from closure is um uh it's bindings this would be if you are if you're using some sort of hints and stuff like that and i think you're going to end up getting what you see kw defaults let's go ahead and do that one whoop there do that that well and let's go and take that one in and we don't have any setup there as well and this goes into depending on how you build out your your function whether you have some variable arguments and things of that nature you really uh the one i ran into was um bases and that would be uh let me see if i can get a class example real quick uh let me do i think i have simple and less simple let's take those two guys let's add those into here and now do um oh there basis i think i can do it at the class level we're gonna find out yes i can oh it's an object so i need to do let's pull ls whoop let me do that whoop dope i can remember how i'm doing stuff um oh and so he doesn't have oh so i do have to do it up at the class level and i should see oh oh i'm sorry i didn't actually do inheritance my mistake so let's say less simple inherits from simple uh let me remember the let me just do it this way let's take these guys that'll be easier uh extras let's go here whoop and we're going to bring this guy and now let's do less simple and now we see that it actually has a base of simple before so if i do simple which is what i had before then there's nothing it's only an object you can just see where that is our object now if i do um and let me show you this so if i do less simple and then i even do even less simple which inherits from less simple and then come in here because this gets to the point of the actual question they had so if i look at even less simple when i look at bases it doesn't give me the hierarchy it gives me what it inherits from so if i use multiple inheritance so if i did less simple and simple then it's going to show me both of them but this shows you when you do basis this is what directly do you inherit from it doesn't necessarily show you the inheritance hierarchy it is what is your parent and that which you know we see every class the parent is at least object and that was one of the things on the test um or at least the example that i looked at so these are things that came up as items that were on the test that i had not covered as much in some of these prior ones another caveat as this may be i said i may do one more we'll have to see i'll see how i feel about it or what i come across when i go through uh doing the certification test uh actually probably do another i'll probably do a couple of samples and maybe even take the test before i do a wrap-up review of this series another thing that i've noticed in looking through taking some of the questions is read them thoroughly there are some that i guess i would call trick questions because they do something that uh either in the name or in like maybe overwriting a variable or something like that it's sort of it looks very straightforward but if you're not paying close attention to the variable names and things like that then you may you'll get confused fairly easily another one is to know which we haven't spent a ton of time i've seen some you've seen some examples of it is when things are uh invalid when you're gonna get errors uh such as i probably had one up here not too far back yeah kinds of things like this where you're going to get an error of some port sort as opposed to the code actually running or the code like a and that would be things like if you do divide by zero and things like that knowing what are you going to see what is it going to tell you roughly so if i did if i go to here and i do 1 over 0 a string of 1 over 0. well actually i don't even have to do that i can just do x equals one divided by zero then i'm gonna get a division by arrow division by zero error so those sorts of things be sure you're so comfortable with what's going to blow it up and what is gonna give you something else yeah and it and some of it is math stuff so if i do that then i note here that okay that's just gonna give me zero over one um those are the things that i think show up in sort of understanding the exceptions they can be stuff that we overlook a little bit but when we get into the test those are the kinds of things they will ask you about and when you look at passing uh just having more comfort with those and particularly this is if you're doing if you do a lot of examples you do a lot of coding just sort of flying through not copying and pasting stuff but actually going through and writing and modifying code you'll run into enough of these they will become sort of second nature to you they'll seem like much easier questions which goes to going through this series is i would think very helpful but because we because of the topics we cover to give you a good idea of what needs to be in your head when you get into the certification but that being said there are there is a lot to be gained by playing around so take these uh and this all this stuff is out in the repository um and you can see links to the the github repository for this uh in the show notes take a look at them maybe write a couple little apps of your own that just do some little utility things or something like that playing around with a lot of this stuff so that you can get a feel for how these things work and really embed it in your mind a little bit more yeah there's one thing to hear about it and see it it's usually a lot more a lot gonna be retained better if you do it and i think i've gone long enough i've been long-winded enough this time so i'm gonna go uh i'm gonna go play around and see if i can get up get my certification and then come back around and let you guys know how it went but go out there have yourself a great day a great week and we will talk to you next time you
Transcript Segments
[Music]
well hello and welcome back we are
continuing our series of episodes on
getting your python certification
and we're getting really close to the
end this may be the last one other than
sort of like a summary
and the thing that i want to swing back
around to is when we did functions
we touched on
properties of a function
and we did this with modules as well
but
i want to make sure that we go back
through those because there are some
questions on those that i found at least
in the sample test
and i think it's good to
make sure you've touched on each of
those
and there's several
so for this example um i just created
this function called myfunk it's got a
couple parameters
it prints something and let me return
something too just to be
complete
so there you go so it prints it it
returns it
so if i call my func
two comma three
then we'll see what happens
so
if i do that the first one i look at is
under score underscore str
so if we do
uh python three extra is that what i
call it
there we go
then we see that it just i called it it
did a little print it returns it if i do
it as a string
then right now since i haven't defined
it in any specific way
then it's going to give me
basically it's a you know the name and
the um
the memory address that exists at
so string is not terribly
interesting um generally speaking for
functions
that you can do let me give you a couple
of these
but another one we can do
is we can do doc
and let me do
let me do this one at a time so let's do
doc
and there's nothing there uh here
there's nothing there is no dock that's
available
and we haven't really talked about this
but what i can do is i can come up here
and
mention that
that
prints
a plus b
oops
b and returns it
[Music]
so now if i come through
um
oh it may be without that
sorry it's a string
so um
the string is a function oh let's do
this
actually let's get more specifically
so what we see here is some of these are
some of these underscores are functions
and some are attributes
um you can see here um
string is a function
but i if i call it
then it gives me
this
with the dock i can actually see
comments and if i do this triple
triple double quote
then that is a built-in
dock it is
built-in comments for
your your function your uh your method
if you're dealing with the client your
class
so it's one of those things we haven't
touched on when you talk about comments
and documentation but that triple quote
triple double quote which is itself sort
of difficult
allows you to do that kind of stuff
it allows you to also then have it
exposed you can come back later and do
you know documentation related stuff
through the dock
so let's pick
uh let's go here
let's do another
uh next one we'll do is let's go ahead
and do
code i think we have
done code
and
it's a
code is an object um i think i need to
get
let's see
i don't know if that's gonna work let's
try this real quick i think you could
get it
uh no it just gives me a code object
so it doesn't give it in a i don't get
in a string format
but what i do get is i get this code
object so i could actually when we talk
about lambdas and think lambdas and
things like that i could actually do
stuff
with that
i can actually push stuff around and
actually call things
based on that
again it's so that you can get all of
the different you can actually dissect
basically your functions
uh annotations i didn't see anything on
it but there are
i haven't really gone into annotations
too much
but you can get that if you have those
call is going to actually call it
so
instead of doing this way you could
actually do it as a call which makes
very little sense we've talked about
class
if we look at defaults that's one i'm
pretty sure that's up there let's see so
we did doc
so we're seeing what we did oh now we
did name
oh let's do call name
let's do that first well if we do
defaults just because i was taking that
in order there aren't any
because i didn't do it but if i do a
equals zero
b equals zero
then i can see what my default values
are
so i can see what the defaults are if
i'm trying again if i'm trying to
dynamically create stuff i can figure it
out through there
uh let's do call name
oh we did string we didn't do names so
if i do
let's look at name
and call name
if we look at those two
then it's going to be the same one um
it depends it basically depends on
whether or not you're within a module or
something like that then you can see
you can see things that get aliased out
but if you want to actually get the name
of the function so string is a string of
the function
the or underscore underscore str it's
the function itself it's not
you know the name
so normally you're going to want to work
with the name instead of the name or the
call name
uh the mod we've talked about module we
see defaults code
and note here this is the
it's the compiled function body
but you can also actually
replace stuff on the fly
um
let's do globals
and what we're going to see here
if we jump to this one is
uh starting here to
here
um these are all the different things we
can call on it and we've seen this
before with when we're looking at
classes
but you can see here that it's like some
of the things we've seen we've got name
a main a doc
which is yeah none
uh what package you're in
uh loader the blah blah blah blah blah
we talked about now supplications let's
do spec
and
um
so let's do
let's pick up a couple of these let's go
look at
spec
and let's look at
let's see
let's do file
so if we look at those two
uh it doesn't have
a spec attribute
um even though it
is there it's because it's not oh there
it is because it is none but i could
write to it uh file file file and it's
gonna show what file it's in so let's
get that
uh oh it doesn't have it
um which is interesting even though it
says here oh it's a global these are the
globals available to it
so i can take aldo so i can see
uh it's not this
if i do this
then i get to see it so i'm sorry those
are
um these are all the globals that are
available within that function
uh
so we've got
uh dictionary is one that we uh let's go
here dick
which is my funk so
oh
so if we do the dictionary let's take a
look at that guy
so see here it doesn't have anything uh
this is really not anything
notable of it
um
where'd it go
but it's basically for uh
if i had an additional attribute within
the function if i did
let's try like name equals
this function
i think then we will see that it'll show
up
nope nope it doesn't because it's not oh
because it's an attribute of the
function that we we could add to we
haven't
so it would be more like
my funk dot
um
[Music]
equals
custom value
and i think now i'll see yep there we go
so i can remember these things are all
dynamic so i can actually add stuff i
can slap all kinds of attributes onto
things
and so dictionary gives me that
let's see closure
be the last one
of these
whoop just do it this way
and let's take a look at that after our
little custom value and there isn't any
because what you get from closure
is um
uh it's bindings this would be if you
are
if you're using some sort of hints and
stuff like that and i think you're going
to end up getting what you see kw
defaults let's go ahead and do that one
whoop
there
do that that
well
and let's go and take that one in and we
don't have any setup there as well
and this goes into
depending on how you build out your
your function whether you have some
variable arguments and things of that
nature
you really uh the one i ran into
was
um
bases
and that would be
uh let me see if i can get a class
example real quick
uh let me do i think i have simple and
less simple let's take those two guys
let's add those into here
and now do
um
oh there basis i think i can do it at
the class level we're gonna find out
yes i can
oh it's an object so i need to do
let's pull ls
whoop
let me do that
whoop
dope
i can remember how i'm doing stuff
um
oh and so he doesn't have oh so i do
have to do it up at the class level
and i should see oh
oh i'm sorry i didn't actually do
inheritance my mistake so let's say less
simple inherits from simple
uh
let me remember the
let me just do it this way let's take
these guys that'll be easier
uh
extras
let's go here
whoop
and we're going to bring this guy and
now
let's do less simple
and now we see
that it actually has a base of
simple
before
so if i do
simple
which is what i had before
then there's nothing it's only an object
you can just see where that is our
object now if i do um and let me show
you this so if i do less simple
and then i even do
even less simple which inherits from
less simple
and then come in here
because this gets to the point of the
actual
question they had
so if i look at even less simple
when i look at bases
it doesn't give me the
hierarchy it gives me what it inherits
from
so if i use multiple inheritance so if i
did less simple and simple
then it's going to show me both of them
but this shows you when you do basis
this is
what directly do you inherit from it
doesn't necessarily show you the
inheritance hierarchy it is what is your
parent
and that which you know we see every
class
the parent is at least object
and that was one of the things on the
test
um or at least the example that i looked
at
so these are things that came up as
items that were on the test that i had
not
covered as much in some of these prior
ones
another caveat as this may be i said i
may do one more we'll have to see i'll
see how i feel about it or what i come
across when i go through uh doing the
certification test
uh actually probably do another i'll
probably do a couple of samples and
maybe even take the test before i do a
wrap-up
review of this series
another thing that i've noticed in
looking through taking some of the
questions
is
read them
thoroughly
there are some
that i guess i would call trick
questions
because they do something that
uh either in the name or
in
like maybe overwriting a variable or
something like that it's sort of
it looks very straightforward but if
you're not paying close attention to the
variable names and things like that then
you may you'll get confused fairly
easily
another one is to know
which we haven't spent a ton of time
i've seen some you've seen some examples
of it is when things are uh invalid
when you're gonna get
errors uh such as i probably had one up
here not too
far back yeah
kinds of things like this where you're
going to get
an error of some port sort as opposed to
the code actually running or the code
like a and that would be things like if
you do divide by zero and things like
that
knowing what
are you going to see what is it going to
tell you roughly so if i did
if i go to here and i do
1 over 0
a string of 1 over 0. well actually i
don't even have to do that i can just do
x equals one divided by zero
then i'm gonna get a division by arrow
division by zero error so those sorts of
things be sure you're so comfortable
with what's going to blow it up and what
is gonna give you something else
yeah and it and some of it is
math stuff so if i do that
then i note here that okay that's just
gonna give me zero over one um those are
the things that i think show up in sort
of understanding the exceptions they can
be stuff that we overlook a little bit
but when we get into the test those are
the kinds of things they will ask you
about and
when you look at passing uh just having
more comfort with those
and particularly this is if you're doing
if you do a lot of examples you do a lot
of coding just sort of flying through
not copying and pasting stuff but
actually
going through and writing and modifying
code
you'll run into enough of these they
will become sort of second nature to you
they'll seem like much easier questions
which goes to
going through this series is i would
think very helpful
but because we because of the topics we
cover to give you a good idea of what
needs to be in your head when you get
into the certification
but that being said there are
there is a lot to be gained by
playing around so take these uh and this
all this stuff is out in the repository
um and you can see links to the the
github repository for this uh in the
show notes
take a look at them maybe write a couple
little apps of your own that just do
some little utility things or something
like that
playing around with a lot of this stuff
so that you can get a feel for
how these things work and
really
embed it in your mind a little bit more
yeah there's one thing to hear about it
and see it it's usually a lot more a lot
gonna be retained better if you do it
and i think i've gone long enough i've
been long-winded enough this time so i'm
gonna go uh i'm gonna go play around and
see if i can get up get my certification
and then come back around and let you
guys know how it went
but
go out there have yourself a great day a
great week and we will talk to you
next time
you