1 00:00:00,740 --> 00:00:07,200 Welcome to this tutorial on the data types strings in Python. 2 00:00:07,280 --> 00:00:16,310 String is a sequence of Unicode characters in Unicode was introduced to include every character in all 3 00:00:16,310 --> 00:00:20,350 languages and bring uniformity in encoding. 4 00:00:21,650 --> 00:00:27,070 And strings in Python can contain as many characters as you wish. 5 00:00:27,080 --> 00:00:35,820 The only limit is your machines memory resources Python does not have a character data type. 6 00:00:36,870 --> 00:00:39,070 Like other programming languages. 7 00:00:39,210 --> 00:00:45,420 A single character is simply a string which has a length of 1 8 00:00:48,650 --> 00:00:57,020 and strings in Python can be created by enclosing inside single code or double code 9 00:01:00,770 --> 00:01:08,710 so if you enclose this text in Edo single code or double code. 10 00:01:08,740 --> 00:01:17,930 This is considered a string in python c is the case for this text now. 11 00:01:17,930 --> 00:01:19,690 Consider this text. 12 00:01:19,750 --> 00:01:22,130 It's a long work. 13 00:01:22,130 --> 00:01:31,130 Now in order to be considered as a string in Python I'm going to enclose this text in single code. 14 00:01:31,460 --> 00:01:41,120 It's a long walk so as but a discussion we have said that a string is something that can be enclosed 15 00:01:41,150 --> 00:01:43,670 in a single code or double quote. 16 00:01:44,000 --> 00:01:54,290 And once the Python interpreter read this text these string opens with a single code and the Python 17 00:01:54,290 --> 00:02:00,490 interpreter assumes the next single code in the text is the closing delimiter. 18 00:02:02,450 --> 00:02:10,930 The single code to your the final single code is then tree and causes a syntax error. 19 00:02:11,100 --> 00:02:13,760 So let's see this in the Jupiter notebook. 20 00:02:15,330 --> 00:02:27,330 So here we have our Jupiter notebook open and I have defined a string as these are one and the it points 21 00:02:27,360 --> 00:02:28,140 to the text. 22 00:02:28,260 --> 00:02:39,060 It's a long work and it is enclosed in single quotes Mullett executed this line and the code has been 23 00:02:39,060 --> 00:02:45,730 interrupted with the syntax error Invalid syntax. 24 00:02:45,780 --> 00:02:56,290 That's because the final single code is a straight and this is causing the syntax error. 25 00:02:56,740 --> 00:03:10,170 So in order to avoid this error what we can do is we can enclose this string in double quotes so let 26 00:03:10,680 --> 00:03:15,570 enclose the text in double codes and now print it out. 27 00:03:16,440 --> 00:03:19,210 So there is no error here. 28 00:03:19,320 --> 00:03:27,480 If there is a single code which is used within a string then we can delimit the string with double quotes 29 00:03:28,470 --> 00:03:33,380 and if there are double codes that are used within the string. 30 00:03:33,450 --> 00:03:37,800 In that case you can use the delimited single code 31 00:03:41,920 --> 00:03:50,510 now coming back to strings we can access individual characters using indexing. 32 00:03:50,540 --> 00:03:51,890 So what is indexing 33 00:03:54,670 --> 00:04:02,900 so for example I've defined a string E with the text. 34 00:04:03,060 --> 00:04:10,470 Now I would like to retrieve the third character in the string. 35 00:04:10,680 --> 00:04:13,680 The third character is B. 36 00:04:13,810 --> 00:04:15,940 So how do we do this. 37 00:04:15,940 --> 00:04:18,220 This can be done using indexing 38 00:04:21,450 --> 00:04:30,230 index start from zero and get incremented with each individual character in the string. 39 00:04:30,270 --> 00:04:35,730 Now in order to leave the letter B the format is 40 00:04:38,450 --> 00:04:41,260 E O squared. 41 00:04:41,370 --> 00:04:48,440 Brackets and the index number or the letter B which is to 42 00:04:51,430 --> 00:05:06,360 here it is the syntax for indexing is the variable which is pointing to the string happy and the index 43 00:05:06,360 --> 00:05:16,220 number is enclosed in square brackets and your rewrite the index number within the square brackets. 44 00:05:16,300 --> 00:05:19,260 Let's check indexing in the Jupiter book. 45 00:05:19,290 --> 00:05:26,040 So I've defined a where you've been e happy which is a string executed. 46 00:05:26,060 --> 00:05:38,390 Now I would like to index or retrieve the letter B which has an index to so within this grade bracket 47 00:05:38,870 --> 00:05:41,270 I'm going to do but the number two 48 00:05:44,410 --> 00:05:47,170 and to the letter B has been to. 49 00:05:48,280 --> 00:05:59,320 And this is the syntax for indexing the variable a is pointing to the string happy and then the index 50 00:05:59,320 --> 00:06:08,480 number is surrounded by square brackets in this retrieves the letter B. 51 00:06:11,720 --> 00:06:17,880 If you try to access a character out of range then it will raise an index error. 52 00:06:18,160 --> 00:06:28,770 So let's say variable is pointing to the string happy which contained so five characters let's say eight 53 00:06:28,850 --> 00:06:42,340 or six let's see what the interpreter does so since there are only five characters in the string a it 54 00:06:42,340 --> 00:06:44,540 has drawn the index into 55 00:06:49,410 --> 00:06:56,710 and also the index must be an integer we can't used flawed or other types. 56 00:06:56,880 --> 00:07:08,860 This will result in two or type error so giving plot numbers or any other data types results in type 57 00:07:08,940 --> 00:07:19,240 error Python allows negative indexing for it sequences the index of minus one refers to the last item 58 00:07:19,870 --> 00:07:23,700 minus 2 to the second last item and so on 59 00:07:28,800 --> 00:07:38,380 say for example we want to retrieve the letter B again using negative indexing we can do minus three 60 00:07:38,830 --> 00:07:47,680 in this grade bracket and at the same as e all do so let's check this in the Jupiter non book 61 00:07:50,980 --> 00:08:06,230 let's do a full minus three so the same letter has been on the tree lit so to the next 62 00:08:09,000 --> 00:08:13,800 letter B so that would be minus two. 63 00:08:13,960 --> 00:08:15,330 This is about a nixing.