- [Narrator] Next we're going to take a look
at a couple of methods that enable you
to look at the characters within a string
and see if they match certain characteristics.
Now those of you coming from other programming languages
may recognize methods or functions like isdigit.
In this case, in Python, isdigit is going
to check every single character within the string
and see if that character is a digit.
And only if all of them are digits
will this method return true.
So as you can see here, we get false
because the minus sign is not itself a digit.
However, if I go ahead and remove the minus sign
and execute that, you can see that indeed we get true.
Now here's another one, the is A-L-N-U-M,
is alphanumeric, so is it a number or a letter.
In this case, everything in this string
is a number or a letter.
And if I take a look at another call similar to that,
if we look at that briefly, we might say,
yeah, those are all letters and numbers,
but there's also a couple of spaces
in this particular string, so we get false on this one.
So methods like these can be used for example
if you're validating data either via user input
or perhaps you're reading data into an application
to get ready to analyze it and you need
to validate certain fields within the data.
And there's a whole bunch
of these character testing methods.
Let me just switch over to a Adobe Acrobat PDF file here
in which we have a table of some of these methods.
And I'm not going to read through
all of them with you right now.
If you'd like, you can go ahead and pause the video
and take a look at this table, but as you can see,
we have a number of different methods that enable us
to validate the characters within a string.
And then each of these methods is going to return
true or false depending on those values.