1 00:00:01,240 --> 00:00:02,460 - [Narrator] Next we're going to take a look 2 00:00:02,460 --> 00:00:05,520 at a couple of methods that enable you 3 00:00:05,520 --> 00:00:08,340 to look at the characters within a string 4 00:00:08,340 --> 00:00:11,180 and see if they match certain characteristics. 5 00:00:11,180 --> 00:00:14,560 Now those of you coming from other programming languages 6 00:00:14,560 --> 00:00:19,170 may recognize methods or functions like isdigit. 7 00:00:19,170 --> 00:00:22,290 In this case, in Python, isdigit is going 8 00:00:22,290 --> 00:00:25,720 to check every single character within the string 9 00:00:25,720 --> 00:00:28,450 and see if that character is a digit. 10 00:00:28,450 --> 00:00:31,320 And only if all of them are digits 11 00:00:31,320 --> 00:00:33,620 will this method return true. 12 00:00:33,620 --> 00:00:35,440 So as you can see here, we get false 13 00:00:35,440 --> 00:00:39,430 because the minus sign is not itself a digit. 14 00:00:39,430 --> 00:00:42,080 However, if I go ahead and remove the minus sign 15 00:00:42,080 --> 00:00:46,230 and execute that, you can see that indeed we get true. 16 00:00:46,230 --> 00:00:50,330 Now here's another one, the is A-L-N-U-M, 17 00:00:50,330 --> 00:00:54,680 is alphanumeric, so is it a number or a letter. 18 00:00:54,680 --> 00:00:56,770 In this case, everything in this string 19 00:00:56,770 --> 00:00:59,010 is a number or a letter. 20 00:00:59,010 --> 00:01:03,100 And if I take a look at another call similar to that, 21 00:01:03,100 --> 00:01:05,320 if we look at that briefly, we might say, 22 00:01:05,320 --> 00:01:07,250 yeah, those are all letters and numbers, 23 00:01:07,250 --> 00:01:09,350 but there's also a couple of spaces 24 00:01:09,350 --> 00:01:13,150 in this particular string, so we get false on this one. 25 00:01:13,150 --> 00:01:16,870 So methods like these can be used for example 26 00:01:16,870 --> 00:01:20,980 if you're validating data either via user input 27 00:01:20,980 --> 00:01:24,020 or perhaps you're reading data into an application 28 00:01:24,020 --> 00:01:26,120 to get ready to analyze it and you need 29 00:01:26,120 --> 00:01:29,010 to validate certain fields within the data. 30 00:01:29,010 --> 00:01:30,350 And there's a whole bunch 31 00:01:30,350 --> 00:01:33,020 of these character testing methods. 32 00:01:33,020 --> 00:01:38,020 Let me just switch over to a Adobe Acrobat PDF file here 33 00:01:38,443 --> 00:01:41,330 in which we have a table of some of these methods. 34 00:01:41,330 --> 00:01:43,030 And I'm not going to read through 35 00:01:43,030 --> 00:01:44,840 all of them with you right now. 36 00:01:44,840 --> 00:01:47,620 If you'd like, you can go ahead and pause the video 37 00:01:47,620 --> 00:01:50,260 and take a look at this table, but as you can see, 38 00:01:50,260 --> 00:01:53,700 we have a number of different methods that enable us 39 00:01:53,700 --> 00:01:57,560 to validate the characters within a string. 40 00:01:57,560 --> 00:02:02,110 And then each of these methods is going to return 41 00:02:02,110 --> 00:02:05,563 true or false depending on those values.