📺 Develpreneur YouTube Episode

Video + transcript

Python Certification Training - String Functions

2021-07-15 •Youtube

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
1.32

[Music]

26.24

well hello and welcome back

27.76

we are continuing our season our series

29.92

where we look at

31.76

the python certification course and

34.16

what's on the test

35.2

what is on the syllabus and we're going

37.04

to walk through examples of

39.2

all of the stuff that's out there this

41.68

episode

42.48

we're going to start we'll see how far

43.6

we can get that's maybe a multi-episode

45.6

one

46.64

probably will because we're going to

47.68

talk about strings

50.239

really taking another step into its

53.039

strings in detail

54.64

so we've touched on them a little bit

56.64

we're going to talk about some of the

57.6

functions

58

related to them and you know

60.16

manipulating working strings

62.48

and just getting into all the little

64.879

bits and pieces of it

67.119

so first off uh we're just going to go

70

with this so we've got just we're going

71.2

to start from our simple one here so

72.88

simple string output and we've seen

76.08

where we can print that out to the

77.28

screen

78

and the first thing we're going to do is

79.36

we're going to look at upper and upper

83.6

will convert everything to uppercase

87.36

so you can see here that's that

90.64

and let me just do whoops

97.28

do it like that and so now let's uh

100.88

yeah that's pretty good so now let's

102.72

take the same thing

105.92

and of course where there's an upper

107.6

there is a lower

112.079

and note

115.52

that in both of these

118.96

that um we had a mixed case here so we

123.2

have a capital t

124.399

and then everything else is lowercase

125.84

here everything's uppercase

128.319

with lower everything's lowercase

131.44

now pretty straightforward now what we

134.16

can do

134.959

is um

139.12

let's do

146.08

there's a bunch that we can do here so

147.92

we can say like is

149.92

lower let's start with that let's see if

152

it's a digit

155.76

and there's a bunch of useful things

158

here

160.239

but we can also say is it

168.84

alpha

171.44

that is alpha

173.15

[Music]

175.84

and let's go is i'll do one more with

179.599

this

181.84

uh i think it's alpha numb is that how

184.8

it

187.519

look here alf i'm sorry uh is i don't

191.04

know

191.68

okay so let's look at those bass whoops

197.519

okay

201.12

based on this string again and so if we

204.56

look

206.879

this guy it's not a digit because

209.28

there's not even

210.159

digits in there it's not alpha

214.879

and it's not an alphanumeric so all of

217.36

those are going to come back false

218.64

if we do let's see

222.159

did we do a uh we can do an is lower

226.72

let's do that real quick so if we do

230.319

is lower

235.84

we're going to see that even though

237.04

there are lower

240.239

we'll see that even though they're it's

242.08

false because we have

243.84

this is what we're working with so we've

245.12

got that but if we were to do is lower

248.64

uh x dot lower

252.239

tide is lower

258

then it's going to come back true

259.84

because we did do that

261.28

now if it's digits uh let's change let's

263.84

do y

264.8

equals one two three four

268

and now let's look at that

276.24

and let's actually do that for each of

278.08

these

279.44

so is add digit is alpha

284.479

and is

292.16

if we look at those we're going to see

294.84

that

298.08

so digit it is true but the alpha

302.16

but is all numb it's going to be true

304.88

but now if i mix

305.84

let me get a z so i can get an alpha

307.919

numeric

309.199

and notice that you have to

312.639

alpha america is it has to be both

316.24

alpha characters a through z basically

318.88

and

320.24

one two and a numeric and so we're gonna

322.32

see here

324.479

if we want to do is alpha just put into

326.88

z

333.84

then we'll see oh that's saying it's not

336.24

alpha either

337.039

interesting so if we look at that

346.16

so that's alphanumeric uh let's see

350.08

oh there we go is alpha if it's an

353.36

alphabetic

354.16

string if all characters stringer

355.84

alphabet i'm sorry

359.36

that's the problem is alphabetic

363.68

has to be no spaces because we have

366.88

spaces here

368.479

it's not pure letters now z is going to

370.8

be true

372.56

there we go so alpha

376.319

so i forgot about so this is uh so

379.68

is alnum is going to be where if you

381.919

have a mix of

383.12

uh numbers and letters

386.4

so you've if it's uh if they are

389.199

alphanumeric and there's at least one

390.639

character in the string

391.84

so you're also going to get let's

394

probably work noting

395.199

that if i do

398.4

a equals empty

402.88

then is

406.84

alpha

409.84

is going to be false and so it's

413.039

actually so is i don't know

416.56

whoops

419.84

that's also a and so we're going to say

421.52

the last of those two are still going to

423.039

be false because

424.4

if it's empty it's not it doesn't know

426.72

what it is

427.68

so it has to be actually it has to fall

429.52

under you know be a valid

432

digit uh alphas string of alphas or

434.96

alphanumeric

438.4

and so um yeah and so then this would be

441.599

our i don't know

443.759

right no that's our l which one was our

445.84

unknown

447.12

so the one that's true is y

451.12

oh which is probably still going to be

452.72

if we do this

455.84

yeah so it doesn't have to have both an

458.479

alpha and a num

459.68

but if we put a space in there then it's

462.8

false

463.84

because it's got to be you can't have

465.44

spaces or special characters

467.28

basically is what we're looking for

468.56

there so

470.479

let's do one other uh

473.599

let's do

478.16

uh let's see what do we want to do with

480.56

this one let's see if we find one more

482.16

is maybe that we haven't

484

looked at uh

487.599

it's printable

491.039

is a neat one

498.4

is printable

503.199

and if we look at x it's going to come

506.08

back and it's going to say it's

507.12

true but if we do this

512.959

now it's false because it's got a

514.56

non-printing character

516.24

in it and you can see here now when we

518.08

added it

519.839

that input before note

523.76

uh it printed here and it just went to

525.76

the next line but here it's actually

527.12

putting that little

528.959

line break which is a non-printing

530.48

character so now it's not printable

534.8

so let's just do x and x 2

541.44

and we'll keep that for posterity sake

548.16

so let's look at another let's look oh

549.519

capitalize so let's take

556.8

let's take a look at this a lot of these

559.12

are useful

559.92

if you find okay

564.8

all right i didn't spell capital that's

566.08

right let me just do it this way because

568.56

i had a brain fart

572.48

so a lot of these you're going to

573.44

actually find are very useful for

574.959

checking for

575.6

validations and stuff like that i go to

578.08

capitalize

579.44

so now it's just capitalizing the first

584.16

um let me do

591.36

uh let me do x3

597.36

equals uh bob jones

602

oh and let's see what happens when it

604.56

capitalizes that so it's now all

609.519

uh lowercase and you see it just

611.519

capitalizes the first letter so that's

612.88

pretty

613.279

it's like upper but only the first

615.44

character

617.12

now one that's useful

620.16

is split that is used

623.36

a lot so let's make this uh this can be

626.079

my string

627.68

equals um

631.04

today is hot

635.36

clear windy

641.279

and so now

649.36

i can take that or is that my string

652.8

right yeah

655.92

so if i do my string dot split

660.16

and now this is going to get a separator

661.92

so now if i take that

663.839

i do a separator which is going to be

666.48

commas

667.519

and now i'm going to do uh result

670.959

equals that and then print result

677.04

let's see what that gives us

681.44

so we're going to see here is it um let

684.16

me just print

685.04

it beforehand

691.92

my string and note that it's uh actually

695.279

i'm going to put it right after here

696.56

so

699.6

note that my strings printing here

702.16

because it's not changing it

704

it's kicking that result back out and

706.32

the result is

707.2

that it splits this into three items on

709.519

the comma

710.56

so today is hot it takes everything

712.8

before the first comma

714.079

clear everything before the second comma

716.399

and then

717.519

wendy is everything after that last

719.12

comma so i could change that if i wanted

721.76

to

723.44

i can make it a pipe

730.639

and if you note before it's taking it's

732.959

not trimming it so you can see here

734.56

there's a space here

736.24

because it was comma space now if i

738.72

remove

739.44

the spaces and i do a split uh

746.56

go here and i just split here we see

750.399

it's those spaces that i removed from

752.24

the string those are not showing up

754.079

anymore so it does today is hot

756.24

you see right here clear you see here

758.72

when do you see here

760.079

and i can print that out that's that's

761.839

just a straight up array so i can do

763.44

print

767.2

result

770.32

let's do two and actually let's do one

774

more thing

775.2

and let's take um

781.72

result.split on space

792.639

oh i'm sorry it's not that's uh i want

795.279

result

796.88

zero so now

800

we're going to see that we come in and

800.959

we split it and

804.16

note that we did uh item two

807.279

so this is an index into array it starts

809.04

at zero so that's going to give us windy

811.44

let me see that and then what i did is i

813.68

turned around took this i said okay

814.959

we'll split that on spaces

816.48

and you'll see that this today is hot

820.72

now the same kind of thing somewhat

824.079

is um we can take

828

my array equals

832.88

uh let's see

838.32

and i don't think we've seen this before

839.92

so i do a b c d

842.72

e f and g h

847.519

and then i do print

852.88

i already got children

858.16

oh sorry that's not what i want oh i'm

861.04

sorry

861.68

i'm looking at something else instead i

863.839

want to do is let me go back

865.76

um from here and now let's put something

868.56

back together so now let's do print

872.16

results 1

875.76

dot join

881.92

with results too

889.76

and uh we're gonna see here

894.48

he's gonna take result one which is

897.279

clear

900.8

and it's going to join it on result two

904.48

which is windy

908.959

and you can see where it's gonna it

913.839

it takes windy uh gosh this is gonna be

916.72

harder to see let me do it this way

918.88

uh because it's sort of hard to see it

921.04

with something that big so let me take

922.399

this

922.959

um let's do so

926.079

m equals o this will be easier to see

934.72

and n equals x

939.759

actually suit and xx

943.12

and then let's do print

946.44

m.join in

953.199

and now we're going to see so the first

956.16

one

958

the string m here we're going to join in

961.92

uh join in the parameter

965.279

so you'll see here um

969.12

that that x x x of the join is it's

971.44

going to take each

972.48

character of that and it's going to

975.6

split it

976.56

across those so n basically is

979.92

shoving o into each or m into each of

982.8

those

983.839

so similar kind of thing it's a little

985.68

bit

986.88

funky to see so let me do q and r

994.32

and so now let's make it o and x

997.759

and let's do o dot join

1000.88

oh wait we'll keep the m's

1005.279

and we're going to do this both ways so

1006.8

you can see a little bit better so i'm

1008.079

going to do

1008.56

q join r

1014.16

and r join q

1017.839

and let's print

1024.48

print r print

1028.079

q

1033.679

and then just to make it a little easier

1035.6

to read

1043.679

and let's do one more

1050.4

because join basically iterates across

1052.24

one into another so if we look at our

1054

r's

1056.16

uh r was first so this is r and this

1059.2

is q so if we do r joins

1062.799

q we're gonna see that there's no

1066.24

you can't shove anything in between

1067.84

these there's nothing there's only one

1069.6

character

1070.48

so if you join with a single character

1072.16

string you're gonna get just the single

1073.679

character string

1074.799

otherwise what it's gonna do is it's

1077.12

gonna try so here

1079.36

uh cue joint r it's going to go to each

1082.4

one of these and try to insert the

1084.32

second string

1085.6

so that's where i get x and then i get

1087.76

an o i get x i get an o i get x then i

1090.24

get an o

1090.88

and then it ends so if i wanted to do

1095.84

uh if that becomes op

1099.039

then i'm going to see xop o-p-o-p

1102.96

see how that works uh and there's some

1105.6

ways that you know this again if you

1106.88

want to

1107.52

play around with strings there's

1109.36

definitely a lot of power that is built

1111.28

in

1112.24

um i'll probably hit on a few more

1116.24

but for right now i think that will

1117.28

cover this one this episode this session

1120.64

and i will come back and do some more

1122.24

sprint strings next time around

1125.12

but as always go out there and have

1126.72

yourself a great day a great week

1128.96

we will talk to you next time

1146.4

you