Detailed Notes
This episode dives into a bunch of built-in string functions you might see on the python certification exam.
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 season our series where we look at the python certification course and what's on the test what is on the syllabus and we're going to walk through examples of all of the stuff that's out there this episode we're going to start we'll see how far we can get that's maybe a multi-episode one probably will because we're going to talk about strings really taking another step into its strings in detail so we've touched on them a little bit we're going to talk about some of the functions related to them and you know manipulating working strings and just getting into all the little bits and pieces of it so first off uh we're just going to go with this so we've got just we're going to start from our simple one here so simple string output and we've seen where we can print that out to the screen and the first thing we're going to do is we're going to look at upper and upper will convert everything to uppercase so you can see here that's that and let me just do whoops do it like that and so now let's uh yeah that's pretty good so now let's take the same thing and of course where there's an upper there is a lower and note that in both of these that um we had a mixed case here so we have a capital t and then everything else is lowercase here everything's uppercase with lower everything's lowercase now pretty straightforward now what we can do is um let's do there's a bunch that we can do here so we can say like is lower let's start with that let's see if it's a digit and there's a bunch of useful things here but we can also say is it alpha that is alpha [Music] and let's go is i'll do one more with this uh i think it's alpha numb is that how it look here alf i'm sorry uh is i don't know okay so let's look at those bass whoops okay based on this string again and so if we look this guy it's not a digit because there's not even digits in there it's not alpha and it's not an alphanumeric so all of those are going to come back false if we do let's see did we do a uh we can do an is lower let's do that real quick so if we do is lower we're going to see that even though there are lower we'll see that even though they're it's false because we have this is what we're working with so we've got that but if we were to do is lower uh x dot lower tide is lower then it's going to come back true because we did do that now if it's digits uh let's change let's do y equals one two three four and now let's look at that and let's actually do that for each of these so is add digit is alpha and is if we look at those we're going to see that so digit it is true but the alpha but is all numb it's going to be true but now if i mix let me get a z so i can get an alpha numeric and notice that you have to alpha america is it has to be both alpha characters a through z basically and one two and a numeric and so we're gonna see here if we want to do is alpha just put into z then we'll see oh that's saying it's not alpha either interesting so if we look at that so that's alphanumeric uh let's see oh there we go is alpha if it's an alphabetic string if all characters stringer alphabet i'm sorry that's the problem is alphabetic has to be no spaces because we have spaces here it's not pure letters now z is going to be true there we go so alpha so i forgot about so this is uh so is alnum is going to be where if you have a mix of uh numbers and letters so you've if it's uh if they are alphanumeric and there's at least one character in the string so you're also going to get let's probably work noting that if i do a equals empty then is alpha is going to be false and so it's actually so is i don't know whoops that's also a and so we're going to say the last of those two are still going to be false because if it's empty it's not it doesn't know what it is so it has to be actually it has to fall under you know be a valid digit uh alphas string of alphas or alphanumeric and so um yeah and so then this would be our i don't know right no that's our l which one was our unknown so the one that's true is y oh which is probably still going to be if we do this yeah so it doesn't have to have both an alpha and a num but if we put a space in there then it's false because it's got to be you can't have spaces or special characters basically is what we're looking for there so let's do one other uh let's do uh let's see what do we want to do with this one let's see if we find one more is maybe that we haven't looked at uh it's printable is a neat one is printable and if we look at x it's going to come back and it's going to say it's true but if we do this now it's false because it's got a non-printing character in it and you can see here now when we added it that input before note uh it printed here and it just went to the next line but here it's actually putting that little line break which is a non-printing character so now it's not printable so let's just do x and x 2 and we'll keep that for posterity sake so let's look at another let's look oh capitalize so let's take let's take a look at this a lot of these are useful if you find okay all right i didn't spell capital that's right let me just do it this way because i had a brain fart so a lot of these you're going to actually find are very useful for checking for validations and stuff like that i go to capitalize so now it's just capitalizing the first um let me do uh let me do x3 equals uh bob jones oh and let's see what happens when it capitalizes that so it's now all uh lowercase and you see it just capitalizes the first letter so that's pretty it's like upper but only the first character now one that's useful is split that is used a lot so let's make this uh this can be my string equals um today is hot clear windy and so now i can take that or is that my string right yeah so if i do my string dot split and now this is going to get a separator so now if i take that i do a separator which is going to be commas and now i'm going to do uh result equals that and then print result let's see what that gives us so we're going to see here is it um let me just print it beforehand my string and note that it's uh actually i'm going to put it right after here so note that my strings printing here because it's not changing it it's kicking that result back out and the result is that it splits this into three items on the comma so today is hot it takes everything before the first comma clear everything before the second comma and then wendy is everything after that last comma so i could change that if i wanted to i can make it a pipe and if you note before it's taking it's not trimming it so you can see here there's a space here because it was comma space now if i remove the spaces and i do a split uh go here and i just split here we see it's those spaces that i removed from the string those are not showing up anymore so it does today is hot you see right here clear you see here when do you see here and i can print that out that's that's just a straight up array so i can do print result let's do two and actually let's do one more thing and let's take um result.split on space oh i'm sorry it's not that's uh i want result zero so now we're going to see that we come in and we split it and note that we did uh item two so this is an index into array it starts at zero so that's going to give us windy let me see that and then what i did is i turned around took this i said okay we'll split that on spaces and you'll see that this today is hot now the same kind of thing somewhat is um we can take my array equals uh let's see and i don't think we've seen this before so i do a b c d e f and g h and then i do print i already got children oh sorry that's not what i want oh i'm sorry i'm looking at something else instead i want to do is let me go back um from here and now let's put something back together so now let's do print results 1 dot join with results too and uh we're gonna see here he's gonna take result one which is clear and it's going to join it on result two which is windy and you can see where it's gonna it it takes windy uh gosh this is gonna be harder to see let me do it this way uh because it's sort of hard to see it with something that big so let me take this um let's do so m equals o this will be easier to see and n equals x actually suit and xx and then let's do print m.join in and now we're going to see so the first one the string m here we're going to join in uh join in the parameter so you'll see here um that that x x x of the join is it's going to take each character of that and it's going to split it across those so n basically is shoving o into each or m into each of those so similar kind of thing it's a little bit funky to see so let me do q and r and so now let's make it o and x and let's do o dot join oh wait we'll keep the m's and we're going to do this both ways so you can see a little bit better so i'm going to do q join r and r join q and let's print print r print q and then just to make it a little easier to read and let's do one more because join basically iterates across one into another so if we look at our r's uh r was first so this is r and this is q so if we do r joins q we're gonna see that there's no you can't shove anything in between these there's nothing there's only one character so if you join with a single character string you're gonna get just the single character string otherwise what it's gonna do is it's gonna try so here uh cue joint r it's going to go to each one of these and try to insert the second string so that's where i get x and then i get an o i get x i get an o i get x then i get an o and then it ends so if i wanted to do uh if that becomes op then i'm going to see xop o-p-o-p see how that works uh and there's some ways that you know this again if you want to play around with strings there's definitely a lot of power that is built in um i'll probably hit on a few more but for right now i think that will cover this one this episode this session and i will come back and do some more sprint strings next time around but as always go out there and have yourself a great day a great week we will talk to you next time you
Transcript Segments
[Music]
well hello and welcome back
we are continuing our season our series
where we look at
the python certification course and
what's on the test
what is on the syllabus and we're going
to walk through examples of
all of the stuff that's out there this
episode
we're going to start we'll see how far
we can get that's maybe a multi-episode
one
probably will because we're going to
talk about strings
really taking another step into its
strings in detail
so we've touched on them a little bit
we're going to talk about some of the
functions
related to them and you know
manipulating working strings
and just getting into all the little
bits and pieces of it
so first off uh we're just going to go
with this so we've got just we're going
to start from our simple one here so
simple string output and we've seen
where we can print that out to the
screen
and the first thing we're going to do is
we're going to look at upper and upper
will convert everything to uppercase
so you can see here that's that
and let me just do whoops
do it like that and so now let's uh
yeah that's pretty good so now let's
take the same thing
and of course where there's an upper
there is a lower
and note
that in both of these
that um we had a mixed case here so we
have a capital t
and then everything else is lowercase
here everything's uppercase
with lower everything's lowercase
now pretty straightforward now what we
can do
is um
let's do
there's a bunch that we can do here so
we can say like is
lower let's start with that let's see if
it's a digit
and there's a bunch of useful things
here
but we can also say is it
alpha
that is alpha
[Music]
and let's go is i'll do one more with
this
uh i think it's alpha numb is that how
it
look here alf i'm sorry uh is i don't
know
okay so let's look at those bass whoops
okay
based on this string again and so if we
look
this guy it's not a digit because
there's not even
digits in there it's not alpha
and it's not an alphanumeric so all of
those are going to come back false
if we do let's see
did we do a uh we can do an is lower
let's do that real quick so if we do
is lower
we're going to see that even though
there are lower
we'll see that even though they're it's
false because we have
this is what we're working with so we've
got that but if we were to do is lower
uh x dot lower
tide is lower
then it's going to come back true
because we did do that
now if it's digits uh let's change let's
do y
equals one two three four
and now let's look at that
and let's actually do that for each of
these
so is add digit is alpha
and is
if we look at those we're going to see
that
so digit it is true but the alpha
but is all numb it's going to be true
but now if i mix
let me get a z so i can get an alpha
numeric
and notice that you have to
alpha america is it has to be both
alpha characters a through z basically
and
one two and a numeric and so we're gonna
see here
if we want to do is alpha just put into
z
then we'll see oh that's saying it's not
alpha either
interesting so if we look at that
so that's alphanumeric uh let's see
oh there we go is alpha if it's an
alphabetic
string if all characters stringer
alphabet i'm sorry
that's the problem is alphabetic
has to be no spaces because we have
spaces here
it's not pure letters now z is going to
be true
there we go so alpha
so i forgot about so this is uh so
is alnum is going to be where if you
have a mix of
uh numbers and letters
so you've if it's uh if they are
alphanumeric and there's at least one
character in the string
so you're also going to get let's
probably work noting
that if i do
a equals empty
then is
alpha
is going to be false and so it's
actually so is i don't know
whoops
that's also a and so we're going to say
the last of those two are still going to
be false because
if it's empty it's not it doesn't know
what it is
so it has to be actually it has to fall
under you know be a valid
digit uh alphas string of alphas or
alphanumeric
and so um yeah and so then this would be
our i don't know
right no that's our l which one was our
unknown
so the one that's true is y
oh which is probably still going to be
if we do this
yeah so it doesn't have to have both an
alpha and a num
but if we put a space in there then it's
false
because it's got to be you can't have
spaces or special characters
basically is what we're looking for
there so
let's do one other uh
let's do
uh let's see what do we want to do with
this one let's see if we find one more
is maybe that we haven't
looked at uh
it's printable
is a neat one
is printable
and if we look at x it's going to come
back and it's going to say it's
true but if we do this
now it's false because it's got a
non-printing character
in it and you can see here now when we
added it
that input before note
uh it printed here and it just went to
the next line but here it's actually
putting that little
line break which is a non-printing
character so now it's not printable
so let's just do x and x 2
and we'll keep that for posterity sake
so let's look at another let's look oh
capitalize so let's take
let's take a look at this a lot of these
are useful
if you find okay
all right i didn't spell capital that's
right let me just do it this way because
i had a brain fart
so a lot of these you're going to
actually find are very useful for
checking for
validations and stuff like that i go to
capitalize
so now it's just capitalizing the first
um let me do
uh let me do x3
equals uh bob jones
oh and let's see what happens when it
capitalizes that so it's now all
uh lowercase and you see it just
capitalizes the first letter so that's
pretty
it's like upper but only the first
character
now one that's useful
is split that is used
a lot so let's make this uh this can be
my string
equals um
today is hot
clear windy
and so now
i can take that or is that my string
right yeah
so if i do my string dot split
and now this is going to get a separator
so now if i take that
i do a separator which is going to be
commas
and now i'm going to do uh result
equals that and then print result
let's see what that gives us
so we're going to see here is it um let
me just print
it beforehand
my string and note that it's uh actually
i'm going to put it right after here
so
note that my strings printing here
because it's not changing it
it's kicking that result back out and
the result is
that it splits this into three items on
the comma
so today is hot it takes everything
before the first comma
clear everything before the second comma
and then
wendy is everything after that last
comma so i could change that if i wanted
to
i can make it a pipe
and if you note before it's taking it's
not trimming it so you can see here
there's a space here
because it was comma space now if i
remove
the spaces and i do a split uh
go here and i just split here we see
it's those spaces that i removed from
the string those are not showing up
anymore so it does today is hot
you see right here clear you see here
when do you see here
and i can print that out that's that's
just a straight up array so i can do
result
let's do two and actually let's do one
more thing
and let's take um
result.split on space
oh i'm sorry it's not that's uh i want
result
zero so now
we're going to see that we come in and
we split it and
note that we did uh item two
so this is an index into array it starts
at zero so that's going to give us windy
let me see that and then what i did is i
turned around took this i said okay
we'll split that on spaces
and you'll see that this today is hot
now the same kind of thing somewhat
is um we can take
my array equals
uh let's see
and i don't think we've seen this before
so i do a b c d
e f and g h
and then i do print
i already got children
oh sorry that's not what i want oh i'm
sorry
i'm looking at something else instead i
want to do is let me go back
um from here and now let's put something
back together so now let's do print
results 1
dot join
with results too
and uh we're gonna see here
he's gonna take result one which is
clear
and it's going to join it on result two
which is windy
and you can see where it's gonna it
it takes windy uh gosh this is gonna be
harder to see let me do it this way
uh because it's sort of hard to see it
with something that big so let me take
this
um let's do so
m equals o this will be easier to see
and n equals x
actually suit and xx
and then let's do print
m.join in
and now we're going to see so the first
one
the string m here we're going to join in
uh join in the parameter
so you'll see here um
that that x x x of the join is it's
going to take each
character of that and it's going to
split it
across those so n basically is
shoving o into each or m into each of
those
so similar kind of thing it's a little
bit
funky to see so let me do q and r
and so now let's make it o and x
and let's do o dot join
oh wait we'll keep the m's
and we're going to do this both ways so
you can see a little bit better so i'm
going to do
q join r
and r join q
and let's print
print r print
q
and then just to make it a little easier
to read
and let's do one more
because join basically iterates across
one into another so if we look at our
r's
uh r was first so this is r and this
is q so if we do r joins
q we're gonna see that there's no
you can't shove anything in between
these there's nothing there's only one
character
so if you join with a single character
string you're gonna get just the single
character string
otherwise what it's gonna do is it's
gonna try so here
uh cue joint r it's going to go to each
one of these and try to insert the
second string
so that's where i get x and then i get
an o i get x i get an o i get x then i
get an o
and then it ends so if i wanted to do
uh if that becomes op
then i'm going to see xop o-p-o-p
see how that works uh and there's some
ways that you know this again if you
want to
play around with strings there's
definitely a lot of power that is built
in
um i'll probably hit on a few more
but for right now i think that will
cover this one this episode this session
and i will come back and do some more
sprint strings next time around
but as always go out there and have
yourself a great day a great week
we will talk to you next time
you