1
00:00:00,390 --> 00:00:03,310
Hello and welcome to this video.

2
00:00:03,540 --> 00:00:08,870
Comments are very important in programming.

3
00:00:09,090 --> 00:00:14,850
They are used to tell you what something does in English.

4
00:00:14,850 --> 00:00:25,770
And they are also used to disable or deactivate parts of your program for testing purposes or parts

5
00:00:25,830 --> 00:00:29,590
that you want to eventually remove from your program.

6
00:00:30,480 --> 00:00:40,170
And in python there are two ways you can implement comments in your program code.

7
00:00:40,170 --> 00:00:43,240
The first is known as a single line comment.

8
00:00:43,350 --> 00:00:50,480
If you want to comment out is single line at a time you use the hash symbol.

9
00:00:50,490 --> 00:00:53,340
We also have the multi line comments.

10
00:00:53,370 --> 00:01:03,030
If you want to implement or comment out multiple line of code you used the three quotes three quotations.

11
00:01:03,400 --> 00:01:11,460
And that will comment out the block of code you have specify the comments to take out.

12
00:01:11,520 --> 00:01:23,340
So let's take a look at how comments work so I have got some lines of code inside my text editor I'm

13
00:01:23,380 --> 00:01:25,060
using item.

14
00:01:25,240 --> 00:01:29,840
This is a file here that I am referring to inside my text editor.

15
00:01:30,490 --> 00:01:37,090
So these are just a bunch of print statements that or print these text on to the console.

16
00:01:37,510 --> 00:01:46,060
So I've also got my command prompt open here on the bottom and my command prompt is basically where

17
00:01:46,720 --> 00:01:49,380
the code will be output head.

18
00:01:49,390 --> 00:01:53,610
So to be displayed in the console here.

19
00:01:53,890 --> 00:02:00,420
So notice here I've changed directory to my desktop because the desktop is where this file is.

20
00:02:00,430 --> 00:02:01,960
This is the file I'm referring to.

21
00:02:02,590 --> 00:02:11,590
If you are on a Mac you need to type in Python 3 followed by the name of your app before you can run

22
00:02:11,590 --> 00:02:11,770
it.

23
00:02:11,770 --> 00:02:17,610
The reason for that is the Mac has bought Python 2 which is pre installed.

24
00:02:17,890 --> 00:02:24,280
And then the Python 3 which you would have installed so you always have to specify which version of

25
00:02:24,280 --> 00:02:27,320
Python you're referring to on the Mac.

26
00:02:27,340 --> 00:02:31,990
So let me printout this program here.

27
00:02:31,990 --> 00:02:33,700
What's inside this file.

28
00:02:33,700 --> 00:02:44,710
Just by calling the file name which is this I just say my app dot P A Y course is a python file an hour

29
00:02:44,720 --> 00:02:46,200
press enter.

30
00:02:46,290 --> 00:02:53,940
I can see hear it as displayed the output from here displaying what's in here.

31
00:02:53,960 --> 00:02:56,280
That's the first line.

32
00:02:56,390 --> 00:02:58,370
This is the last line here.

33
00:02:59,240 --> 00:03:04,580
So let's say I don't want the first line to be displayed.

34
00:03:04,580 --> 00:03:08,410
I want to take out the first two lines and the way we do that.

35
00:03:08,510 --> 00:03:09,760
Just add a comment.

36
00:03:09,800 --> 00:03:14,480
Just use that he can see comments out that line completely.

37
00:03:14,660 --> 00:03:21,200
And if I want to take out the second line as well I just put the hash and that he can see the coloration

38
00:03:21,200 --> 00:03:22,470
has also change.

39
00:03:22,640 --> 00:03:24,620
And that takes out those two lines.

40
00:03:24,620 --> 00:03:35,630
So let me just save that and if I run the program again just by moving the up arrow on my keyboard that

41
00:03:35,630 --> 00:03:37,010
will run it again.

42
00:03:37,010 --> 00:03:42,540
I just PRESENTER Now you can see it starts from here on line three.

43
00:03:42,590 --> 00:03:44,070
That's the text there.

44
00:03:44,180 --> 00:03:45,980
It's not displayed.

45
00:03:45,980 --> 00:03:47,380
Line 1 and 2.

46
00:03:47,690 --> 00:03:49,990
You can see no line 1 and 2 here.

47
00:03:49,990 --> 00:03:52,690
Start from line 3 which is this one.

48
00:03:52,800 --> 00:03:55,620
And on line 6 which is that one.

49
00:03:55,640 --> 00:03:59,300
So that's how you implement a single line comment.

50
00:03:59,420 --> 00:04:02,120
If you want to comment out a single line of code.

51
00:04:02,450 --> 00:04:10,010
Also when you comment when you comment out a line of code you can also write some text just to if you

52
00:04:10,010 --> 00:04:13,050
want to be more descriptive of what it does.

53
00:04:13,190 --> 00:04:20,060
Now you can also have comments that will not impact on the code running.

54
00:04:20,060 --> 00:04:22,330
So for example line three here.

55
00:04:22,430 --> 00:04:25,270
Let me minimize the screen.

56
00:04:25,580 --> 00:04:31,210
Let me clear this to create some space.

57
00:04:31,220 --> 00:04:34,280
Clear that and minimize that.

58
00:04:34,280 --> 00:04:40,010
So let's say on line three here I want to add a comment so I can either comment if you comment on the

59
00:04:40,010 --> 00:04:41,460
right hand side.

60
00:04:41,630 --> 00:04:44,480
It does not impact on the code.

61
00:04:44,510 --> 00:04:45,480
It will not affect that.

62
00:04:45,480 --> 00:04:50,680
You can see it hasn't changed the appearance or the background color.

63
00:04:50,720 --> 00:04:51,170
All right.

64
00:04:51,170 --> 00:04:59,510
So we the idea of putting a comment on the right hand side is that you can then add some text to say

65
00:04:59,960 --> 00:05:01,030
what this line does.

66
00:05:01,030 --> 00:05:05,240
So I can see this line prints this blah blah blah.

67
00:05:05,270 --> 00:05:11,320
So it's just I can then add the descriptive text as to what that line of code does.

68
00:05:11,330 --> 00:05:16,190
So that's how you work with single line comments.

69
00:05:16,190 --> 00:05:23,940
So I'm just going to take that out the single line comment and take this one out as well.

70
00:05:25,790 --> 00:05:27,980
Now we have the multiple line comment.

71
00:05:28,000 --> 00:05:32,930
So let's say you want to I want you to comment out multiple lines.

72
00:05:32,930 --> 00:05:34,340
So let's come here.

73
00:05:35,300 --> 00:05:45,800
So you just two one two three has to be three and then I come here on the bottom and I do one two three

74
00:05:47,120 --> 00:05:50,930
so you can see everything here has turned green.

75
00:05:50,960 --> 00:05:56,630
You can see the print here is no longer highlighted as blue because everything here is now commented

76
00:05:56,630 --> 00:05:56,900
out.

77
00:05:56,900 --> 00:06:01,150
So this is I'm commenting out multiple lines of code at the same time.

78
00:06:01,700 --> 00:06:07,580
So let me save this and then try and run it again in my console.

79
00:06:08,150 --> 00:06:17,300
So again I just type in the name of the app my app dot p y and it should only run the first two line

80
00:06:17,300 --> 00:06:22,730
of code and that's because the other lines are being commented out.

81
00:06:22,730 --> 00:06:23,050
OK.

82
00:06:23,060 --> 00:06:29,960
So this three speak this three here quotes and the three here.

83
00:06:29,960 --> 00:06:33,800
That's how you two a multiple line comment.

84
00:06:34,160 --> 00:06:40,510
And you can also add text to that to describe what you are commenting out.

85
00:06:40,550 --> 00:06:45,920
So comments are very useful if you don't want the code to be affected.

86
00:06:45,920 --> 00:06:52,150
You can obviously use single line comments to comment out on the right hand side.

87
00:06:52,160 --> 00:07:00,500
What that line of code does or you can add multiple line comments and then just write some descriptive

88
00:07:00,500 --> 00:07:06,770
text of what that block of code is doing or is meant to do so.

89
00:07:06,770 --> 00:07:14,670
Comments are very useful because there may come a time you may want to test set in aspects of your code.

90
00:07:14,810 --> 00:07:20,120
You don't want that block of code to run and the way you do that is to just comment out either.

91
00:07:20,150 --> 00:07:28,220
That line of code or the entire block of code and that will prevent that section from executing when

92
00:07:28,220 --> 00:07:29,460
the code runs.

93
00:07:29,510 --> 00:07:34,400
So that's it for this video on using comments in Python.

94
00:07:34,400 --> 00:07:36,610
Thanks for watching and bye for now.
