Hello and welcome to this video.
Comments are very important in programming.
They are used to tell you what something does in English.
And they are also used to disable or deactivate parts of your program for testing purposes or parts
that you want to eventually remove from your program.
And in python there are two ways you can implement comments in your program code.
The first is known as a single line comment.
If you want to comment out is single line at a time you use the hash symbol.
We also have the multi line comments.
If you want to implement or comment out multiple line of code you used the three quotes three quotations.
And that will comment out the block of code you have specify the comments to take out.
So let's take a look at how comments work so I have got some lines of code inside my text editor I'm
using item.
This is a file here that I am referring to inside my text editor.
So these are just a bunch of print statements that or print these text on to the console.
So I've also got my command prompt open here on the bottom and my command prompt is basically where
the code will be output head.
So to be displayed in the console here.
So notice here I've changed directory to my desktop because the desktop is where this file is.
This is the file I'm referring to.
If you are on a Mac you need to type in Python 3 followed by the name of your app before you can run
it.
The reason for that is the Mac has bought Python 2 which is pre installed.
And then the Python 3 which you would have installed so you always have to specify which version of
Python you're referring to on the Mac.
So let me printout this program here.
What's inside this file.
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
press enter.
I can see hear it as displayed the output from here displaying what's in here.
That's the first line.
This is the last line here.
So let's say I don't want the first line to be displayed.
I want to take out the first two lines and the way we do that.
Just add a comment.
Just use that he can see comments out that line completely.
And if I want to take out the second line as well I just put the hash and that he can see the coloration
has also change.
And that takes out those two lines.
So let me just save that and if I run the program again just by moving the up arrow on my keyboard that
will run it again.
I just PRESENTER Now you can see it starts from here on line three.
That's the text there.
It's not displayed.
Line 1 and 2.
You can see no line 1 and 2 here.
Start from line 3 which is this one.
And on line 6 which is that one.
So that's how you implement a single line comment.
If you want to comment out a single line of code.
Also when you comment when you comment out a line of code you can also write some text just to if you
want to be more descriptive of what it does.
Now you can also have comments that will not impact on the code running.
So for example line three here.
Let me minimize the screen.
Let me clear this to create some space.
Clear that and minimize that.
So let's say on line three here I want to add a comment so I can either comment if you comment on the
right hand side.
It does not impact on the code.
It will not affect that.
You can see it hasn't changed the appearance or the background color.
All right.
So we the idea of putting a comment on the right hand side is that you can then add some text to say
what this line does.
So I can see this line prints this blah blah blah.
So it's just I can then add the descriptive text as to what that line of code does.
So that's how you work with single line comments.
So I'm just going to take that out the single line comment and take this one out as well.
Now we have the multiple line comment.
So let's say you want to I want you to comment out multiple lines.
So let's come here.
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
so you can see everything here has turned green.
You can see the print here is no longer highlighted as blue because everything here is now commented
out.
So this is I'm commenting out multiple lines of code at the same time.
So let me save this and then try and run it again in my console.
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
of code and that's because the other lines are being commented out.
OK.
So this three speak this three here quotes and the three here.
That's how you two a multiple line comment.
And you can also add text to that to describe what you are commenting out.
So comments are very useful if you don't want the code to be affected.
You can obviously use single line comments to comment out on the right hand side.
What that line of code does or you can add multiple line comments and then just write some descriptive
text of what that block of code is doing or is meant to do so.
Comments are very useful because there may come a time you may want to test set in aspects of your code.
You don't want that block of code to run and the way you do that is to just comment out either.
That line of code or the entire block of code and that will prevent that section from executing when
the code runs.
So that's it for this video on using comments in Python.
Thanks for watching and bye for now.