1 00:00:00,640 --> 00:00:03,560 Hello 1 Welcome to this video. 2 00:00:03,580 --> 00:00:10,220 In this video I will be talking about the string data type in Python. 3 00:00:10,210 --> 00:00:17,980 Anytime you hear programmers and developers talking about string they are basically referring to text 4 00:00:18,430 --> 00:00:31,210 and characters page string and python is basically a sequence of character data for the computer to 5 00:00:31,210 --> 00:00:35,280 recognize that you are referring to a string. 6 00:00:35,440 --> 00:00:41,210 You have to enclose or surround the text in quotes. 7 00:00:41,260 --> 00:00:47,910 The quotes can be single or they can be double quotes but you cannot mix them. 8 00:00:47,920 --> 00:00:57,520 You can start with a single quote and end with a double quote all characters between the opening and 9 00:00:57,520 --> 00:01:10,550 closing quotes are all part of the string also a string can contain any character you want including 10 00:01:10,640 --> 00:01:20,120 spaces that can also contain backslash and other kinds of characters you want included in your string 11 00:01:21,380 --> 00:01:27,010 a string can also be empty so you can have an empty string. 12 00:01:27,200 --> 00:01:34,990 Just have the quotes and nothing in between the quotes a typical example of his string is hello world. 13 00:01:35,060 --> 00:01:44,900 So the text enclosed in quotes is what the computer we recognize as a string. 14 00:01:44,900 --> 00:01:48,650 If you don't enclose it in quotes the computer will not know what you're talking about. 15 00:01:49,160 --> 00:01:51,220 I have got my command prompt. 16 00:01:51,350 --> 00:01:57,860 If you're on a Mac you need to open up your terminal and type in Python 3. 17 00:01:58,010 --> 00:02:05,090 If you're on a Windows just type in Python to access the python shell and press enter. 18 00:02:05,210 --> 00:02:14,600 I'm just going to use the print statement of function to just print out some text on the screen so I'm 19 00:02:14,840 --> 00:02:22,320 gonna type in print and inside the parentheses for the print function. 20 00:02:22,430 --> 00:02:33,680 I'm going to just print out a simple text and just say hello and as close as you can see I've got the 21 00:02:33,680 --> 00:02:41,090 opening double code and the closing double quote and I'll close in parentheses for the print function. 22 00:02:41,090 --> 00:02:48,920 Now if I press printer nitro just print out hello world without the quotes so you can see he is giving 23 00:02:48,920 --> 00:02:49,850 me text. 24 00:02:49,850 --> 00:02:50,570 Hello world. 25 00:02:50,660 --> 00:02:57,860 So that's how the computer understands that you are talking about his strength so anytime you want to 26 00:02:57,860 --> 00:03:06,210 refer to his string in Python you have to enclose it in the quotes and the codes have to be matching. 27 00:03:06,260 --> 00:03:13,910 You can start with a double code here and then end with a single is you either used to single or you 28 00:03:13,910 --> 00:03:17,130 used to double on either side. 29 00:03:17,210 --> 00:03:21,660 So let's try another example if I say print and in quotes. 30 00:03:21,710 --> 00:03:31,730 I just have a single quote and I just say hey and just close that presenter and you can see just kiss 31 00:03:31,730 --> 00:03:36,770 me Hey so you can use either single or double quote. 32 00:03:36,920 --> 00:03:41,190 What if you have a character that is caught. 33 00:03:41,190 --> 00:03:44,310 Now you want to use an apostrophe. 34 00:03:44,360 --> 00:03:50,830 How would you represent that in a string character. 35 00:03:50,870 --> 00:03:52,100 So this is how you would do it. 36 00:03:52,100 --> 00:04:03,530 So let's say we have the print function and inside that I want to have a string so I can say hey I'm 37 00:04:03,530 --> 00:04:04,530 not typing. 38 00:04:04,640 --> 00:04:06,110 What. 39 00:04:06,160 --> 00:04:11,380 So you use what they call a escape character which is a backslash. 40 00:04:11,380 --> 00:04:22,400 So do that and then add the single quote and I want the s on typing up and then I'll close that by doing 41 00:04:22,400 --> 00:04:23,470 it this way. 42 00:04:23,750 --> 00:04:32,630 It will output the apostrophe with the What's up because I've got I can't use double quotes because 43 00:04:32,630 --> 00:04:38,480 I've already got the double quotes on either side enclosing the string by press enter. 44 00:04:38,570 --> 00:04:40,430 You can see here says what's up. 45 00:04:40,430 --> 00:04:42,980 It's now using the apostrophe. 46 00:04:42,980 --> 00:04:51,230 The only way I was able to achieve that was by using this escape character to escape the sequence and 47 00:04:51,260 --> 00:04:53,960 produce the this here. 48 00:04:54,120 --> 00:04:57,420 OK so that's how you use that character. 49 00:04:57,710 --> 00:05:09,590 All characters in a string has a specific index that is associated to them to identify their position 50 00:05:09,680 --> 00:05:13,430 or location within the string. 51 00:05:13,430 --> 00:05:23,780 So what that means is that you can tell what number a particular string is positioned within a string. 52 00:05:23,780 --> 00:05:28,910 And with Python the index are zero based. 53 00:05:28,910 --> 00:05:35,900 What that means is that the first letter of the first character will be will have the index of 0. 54 00:05:36,020 --> 00:05:38,510 The next will have the index of 1 and so on. 55 00:05:38,510 --> 00:05:42,620 For example now this hedge will have an index of 0. 56 00:05:42,740 --> 00:05:51,020 The position will be 0 and then the E position of the E would be 1 does what is referred to as a zero 57 00:05:51,020 --> 00:05:53,150 based index. 58 00:05:53,150 --> 00:06:04,400 So let's cut to a quick example to see how the index works in Python so I can just do a simple print 59 00:06:04,400 --> 00:06:11,060 statement and inside the parentheses which say hello. 60 00:06:12,620 --> 00:06:13,430 Okay. 61 00:06:13,460 --> 00:06:22,130 And then I'll close the apparently sees and then to find that the position of a specific character I 62 00:06:22,130 --> 00:06:24,350 need to use a square brackets. 63 00:06:24,350 --> 00:06:30,490 So for example I want to find out the position of E in a low. 64 00:06:30,500 --> 00:06:38,090 It will have an index of 1 because the first has an index of 0 so I'll close the square brackets and 65 00:06:38,090 --> 00:06:47,090 close the parentheses for my print function and if I press enter it should return and it should return 66 00:06:47,510 --> 00:06:58,040 the value of E U C so e here as the index of 1 because it's a zero based index so knowing how indexes 67 00:06:58,040 --> 00:07:00,980 works is quite useful as well. 68 00:07:01,010 --> 00:07:09,650 In Python so that is it for this brief introduction to the string data type in Python. 69 00:07:09,650 --> 00:07:10,640 Thanks for watching. 70 00:07:10,970 --> 00:07:11,630 Bye for now.