1 00:00:01,030 --> 00:00:02,470 - [Instructor] Next, we're going to take a look 2 00:00:02,470 --> 00:00:06,600 at what are known as raw strings in Python. 3 00:00:06,600 --> 00:00:09,550 Now you may recall that the backslash character 4 00:00:09,550 --> 00:00:14,140 within a string normally introduces an escape sequence. 5 00:00:14,140 --> 00:00:17,000 So for example, Backslash + n if it were to appear 6 00:00:17,000 --> 00:00:18,990 within a string would represent the 7 00:00:18,990 --> 00:00:21,200 new line escape sequence. 8 00:00:21,200 --> 00:00:25,030 Now, when you're going things like creating file paths 9 00:00:25,030 --> 00:00:27,610 on the Microsoft Windows operating system, 10 00:00:27,610 --> 00:00:30,003 such as the example I just pasted in here, 11 00:00:30,003 --> 00:00:34,430 backslashes are used to separate your folder names. 12 00:00:34,430 --> 00:00:36,400 So, if you're creating a string 13 00:00:36,400 --> 00:00:39,450 that represents a Windows path you would need 14 00:00:39,450 --> 00:00:42,860 to use two backslashes in every location 15 00:00:42,860 --> 00:00:45,690 where a backslash is required in a Windows path 16 00:00:45,690 --> 00:00:50,690 because by default the backslash inside of a string is used 17 00:00:50,810 --> 00:00:52,570 to indicate an escape sequence. 18 00:00:52,570 --> 00:00:53,460 So, you'd actually have 19 00:00:53,460 --> 00:00:56,810 to use the backslash characters escape sequence 20 00:00:56,810 --> 00:00:59,320 to properly encode that string 21 00:00:59,320 --> 00:01:02,700 and if I go ahead and display 22 00:01:02,700 --> 00:01:05,230 that you can see we get the same thing 23 00:01:05,230 --> 00:01:08,170 as we had entered in the string up above here. 24 00:01:08,170 --> 00:01:11,250 Now, that can be really painful to do 25 00:01:11,250 --> 00:01:13,960 when you're dealing with Windows paths a lot, 26 00:01:13,960 --> 00:01:17,540 or as we go into the next sequence of videos 27 00:01:17,540 --> 00:01:20,510 and start to introduce regular expressions. 28 00:01:20,510 --> 00:01:24,050 Backslashes are used in regular expressions 29 00:01:24,050 --> 00:01:26,290 for pattern matching quite a lot. 30 00:01:26,290 --> 00:01:31,290 So, there's a concept in Python called a raw string 31 00:01:31,350 --> 00:01:35,400 and with a raw string it just assumes every character 32 00:01:35,400 --> 00:01:38,810 in the string is its literal value. 33 00:01:38,810 --> 00:01:42,370 So, this is the same file path as a raw string, 34 00:01:42,370 --> 00:01:44,850 which is a string starting with the letter r 35 00:01:44,850 --> 00:01:48,830 before its opening quote and as you can see here I'm 36 00:01:48,830 --> 00:01:53,550 not using double backslashes throughout this Windows path 37 00:01:53,550 --> 00:01:55,070 that I've created. 38 00:01:55,070 --> 00:02:00,070 However, when I evaluate that same path you can see 39 00:02:00,960 --> 00:02:04,910 that it is still creating the string properly 40 00:02:04,910 --> 00:02:06,970 with the two backslashes 41 00:02:06,970 --> 00:02:09,520 at each location underneath the hood. 42 00:02:09,520 --> 00:02:12,190 So, this is a convenience notation 43 00:02:12,190 --> 00:02:14,680 for anytime you're dealing with strings 44 00:02:14,680 --> 00:02:19,260 that can contain literal backslash characters in particular 45 00:02:19,260 --> 00:02:22,934 and other escape character sequences as well 46 00:02:22,934 --> 00:02:25,140 that you simply want to be treated 47 00:02:25,140 --> 00:02:28,513 as their individual character values.