1
00:00:05,180 --> 00:00:10,180
Alright so we finished the last video by getting the text to output all on one line,

2
00:00:10,180 --> 00:00:14,680
even though we've split up our code, and that's the code on lines 13 through 15.

3
00:00:14,680 --> 00:00:17,260
And I'll be talking about code style a bit later,

4
00:00:17,260 --> 00:00:20,740
and we'll see why you might want to split the lines of code up like that.

5
00:00:20,740 --> 00:00:24,020
The good news is that it doesn't just work with triple quotes either.

6
00:00:24,020 --> 00:00:28,920
I can actually split, coming back up here to line 11,

7
00:00:28,920 --> 00:00:30,740
I can split that up as well.

8
00:00:30,740 --> 00:00:33,540
So I'm coming down here to the end of line 11.

9
00:00:33,540 --> 00:00:37,780
So let's do it after the no no, so no no comma.

10
00:00:37,780 --> 00:00:44,300
I'm going to put a space and a backslash there, and press Enter,

11
00:00:44,300 --> 00:00:49,940
and I'll just remove that initial space there at the start so it's directly under, because we've already got a space after the no-no.

12
00:00:49,940 --> 00:00:52,780
So when I run the program,

13
00:00:52,780 --> 00:00:56,980
we still get the whole message on the single line, which is pretty neat.

14
00:00:56,980 --> 00:01:00,740
Alright, so in total that's three ways to delimit strings in your code.

15
00:01:00,740 --> 00:01:06,200
We've also looked at using the escape character, the backslash, to add special characters like a line feed or tab.

16
00:01:06,200 --> 00:01:10,460
But what if you wanted to include the backslash character in your string.

17
00:01:10,460 --> 00:01:12,580
Well, there are a few ways of doing that.

18
00:01:12,580 --> 00:01:14,380
Let's see some examples of that.

19
00:01:14,380 --> 00:01:20,360
So I'm going to come down, firstly, on line 21. Let's make a start, and we're going to type

20
00:01:20,360 --> 00:01:24,740
print parentheses double quotes, and we'll type in our path so

21
00:01:24,740 --> 00:01:36,780
C:\Users\timbuchalka\notes.txt,

22
00:01:36,780 --> 00:01:40,040
then close off the string and the right parenthesis

23
00:01:40,040 --> 00:01:44,840
Now obviously, as I was typing that and looking at it now, clearly there's something funny going on there,

24
00:01:44,840 --> 00:01:49,040
because the IDE, in this case, has highlighted slash users,

25
00:01:49,040 --> 00:01:57,240
and if you look carefully it's also underlining imbuchalka,  and it's saying there's a spelling mistake.

26
00:01:57,240 --> 00:01:59,000
typo in word, as you can see there.

27
00:01:59,000 --> 00:02:02,700
Now what's important about that warning isn't that it's a spelling mistake.

28
00:02:02,700 --> 00:02:05,920
I wouldn't expect any dictionary to contain the word timbuchalka.

29
00:02:05,920 --> 00:02:11,000
Now what's interesting is that it mentions imbuchalka,
without the t.

30
00:02:11,000 --> 00:02:16,680
Because of the backslash character it's interpreting the t of tim as a tab character,

31
00:02:16,680 --> 00:02:21,680
and it's also interpreted the n of notes as a line feed character.

32
00:02:21,680 --> 00:02:24,700
The backslash before Users is also causing problems.

33
00:02:24,700 --> 00:02:31,480
Backslash U also has a special meaning, and it's used to include things like accented characters in your strings.

34
00:02:31,480 --> 00:02:35,220
Okay, so we obviously can't include backslash characters just by typing them,

35
00:02:35,220 --> 00:02:37,360
so let's see two ways we can handle this.

36
00:02:37,360 --> 00:02:41,340
What I'm going to do is duplicate this first line to give us two copies to work with.

37
00:02:41,340 --> 00:02:45,880
So in IntelliJ, command D, sorry ctrl D,  will do it on a PC,

38
00:02:45,880 --> 00:02:47,440
command D on a Mac.

39
00:02:47,440 --> 00:02:51,780
So the first way is to escape the backslash by putting another backslash before it.

40
00:02:51,780 --> 00:02:57,620
So we'll just literally find all the backslashes in the string and add a second backslash.

41
00:02:57,620 --> 00:03:00,940
So that looks better. By escaping the backslash with another backslash,

42
00:03:00,940 --> 00:03:04,440
we've told Python that we want the backslash character to be output.

43
00:03:04,440 --> 00:03:07,460
The second way is to use a raw string.

44
00:03:07,460 --> 00:03:10,640
Raw strings are intended for use with regular expressions,

45
00:03:10,640 --> 00:03:15,840
and we can create a raw string by prefixing the string with the letter r, r for raw .

46
00:03:15,840 --> 00:03:19,100
So I can come up to line 22 now, and put an r there,

47
00:03:19,100 --> 00:03:21,480
and you can see now that that line also looks better.

48
00:03:21,480 --> 00:03:24,960
Now when I run the program,

49
00:03:24,960 --> 00:03:29,280
both lines now print the same thing, with a single backslash in each place.

50
00:03:29,280 --> 00:03:34,040
In general, I'd recommend using the first method, escaping your backslash characters.

51
00:03:34,040 --> 00:03:38,100
We'll see why that's preferable to using raw strings, a bit later in the course.

52
00:03:38,100 --> 00:03:42,980
Alright, so let's finish this video here,
and in the next one, we'll look at variables in Python.

53
00:03:42,980 --> 00:03:45,720
And it turns out we've used a couple of variables already.

54
00:03:45,720 --> 00:03:47,740
Now it's time to learn more about them.

55
00:03:47,740 --> 00:03:50,680
See you in the next video.

