Commenting in Python is also quite different than other languages, but it is pretty easy to get used to. In Python there are basically two ways to comment: single line and multiple line. Single line commenting is good for a short, quick comment (or for debugging), while the block comment is often used to describe something much more in detail or to block out an entire chunk of code.
One Line Comments
Typically, you just use the # (pound) sign to comment out everything that follows it on that line.
Multiple Line Comments
Multiple line comments are slightly different. Simply use 3 single quotes before and after the part you want commented.
Alright, we are done with comments, but don’t forget them. They are your best friend in debugging complex Python code. Now onto the actual programming stuff.
Link/cite this page
If you use any of the content on this page in your own work, please use the code below to cite this page as the source of the content.
Stewart, Suzy. "Comments". After Hours Programming. Accessed on September 22, 2023. https://www.afterhoursprogramming.com/tutorial/python/comments-py/.
Python is possibly the best prgramming language for numerous different reasons. But I honestly can’t be arsed to explain those atm so have fun coding boiii!!
Python is possibly the best prgramming language for numerous different reasons. But I honestly can’t be arsed to explain those atm so have fun coding boiii!!
Python is possibly the best prgramming language for numerous different reasons. But I honestly can’t be arsed to explain those atm so have fun coding boiii!!
Python is possibly the best prgramming language for numerous different reasons. But I honestly can’t be arsed to explain those atm so have fun coding boiii!!
So comments for python is like a hidden define to tell the user after over 1k lines what this part of the code is responsible for? Random question how did you get the 3 quote signs?
Kudos, extreme kudos sir, for adding a code simulator that is actually accessible to screenreaders. This fact alone has blown away big contenders like CodeAcademy for me, a blind screenreader user. Keep rocking 🙂
In Python 3.4.3 shell has the syntax for multiple line comments changed? This is what I got: >>> ”’ print(“We are in a comment”) print (“We are still in a comment”) ”’ print(“We are out of the comment”) SyntaxError: multiple statements found while compiling a single statement >>>
—
Also when trying only multiple comments without including the print command, I get this: >>> ”’ print(“We are in a comment”) print (“We are still in a comment”) ”’ ‘ print(“We are in a comment”) print (“We are still in a comment”) ‘ >>>
”’ print(“We are in a comment”) print(“We are still in a comment”) ”’ displayed this ‘ print (“We are in a comment”) print (“We are still in a comment”) ‘ while print(“We are out of the comment”) print the comment separately. why not together?
hi
Porn! Is good! For your sexual desires!
Porn! Is good! For your sexual desires!
Porn! Is good! For your sexual desires!
Python is possibly the best prgramming language for numerous different reasons. But I honestly can’t be arsed to explain those atm so have fun coding boiii!!
Python is possibly the best prgramming language for numerous different reasons. But I honestly can’t be arsed to explain those atm so have fun coding boiii!!
Python is possibly the best prgramming language for numerous different reasons. But I honestly can’t be arsed to explain those atm so have fun coding boiii!!
Python is possibly the best prgramming language for numerous different reasons. But I honestly can’t be arsed to explain those atm so have fun coding boiii!!
print(“not a comment”)
#print(“Am aa comment”)
“‘
print(“We’re in the comment”)
print(“we’re still in thew comment”)
“‘
print(“out a comment”)
print(“not a comment”)
#print(“Am aa comment”)
“‘
print(“We’re in the comment”)
print(“we’re still in thew comment”)
“‘
print(“out a comment”)
print(“not a comment”)
#print(“Am aa comment”)
print(“not a comment”)
#print(“Am aa comment”)
print “testing”
#test plan
print(“Me:)#oh my
So comments for python is like a hidden define to tell the user after over 1k lines what this part of the code is responsible for? Random question how did you get the 3 quote signs?
Kudos, extreme kudos sir, for adding a code simulator that is actually accessible to screenreaders. This fact alone has blown away big contenders like CodeAcademy for me, a blind screenreader user. Keep rocking 🙂
”’
print (“We are in a comment”)
print (“We are still in a comment”)
”’
print (“we are out of the comment”)
In Python 3.4.3 shell has the syntax for multiple line comments changed? This is what I got:
>>> ”’
print(“We are in a comment”)
print (“We are still in a comment”)
”’
print(“We are out of the comment”)
SyntaxError: multiple statements found while compiling a single statement
>>>
—
Also when trying only multiple comments without including the print command, I get this:
>>> ”’
print(“We are in a comment”)
print (“We are still in a comment”)
”’
‘
print(“We are in a comment”)
print (“We are still in a comment”)
‘
>>>
# is hash sign and not pound £ sign?
”’
print(“We are in a comment”)
print(“We are still in a comment”)
”’
displayed this
‘
print (“We are in a comment”)
print (“We are still in a comment”)
‘ while print(“We are out of the comment”) print the comment separately. why not together?
“”print(“We are in a comment!”)
print (“im happy”)
#comments are important
”’
multilple line comments are
even more important
when there is a lot to say
”’
The code simulator on this page doesn’t recognize blank lines,
or tab or print(‘ ‘).
”’
Show 2 blank lines before printing to the console “Two Blank Lines”
”’
print(”
Two Blank Lines”)
Ok I tried using 3 pairs of quotes (which works as well) and I get this now:
“””
print(“We are in a comment”)
print (“We are still in a comment”)
“””
print(“We are out of the comment”)
‘
print(“We are in a comment”)
print (“We are still in a comment”)
‘
So I typed this into IDLE
”’
print(“We are in a comment”)
print (“We are still in a comment”)
”’ print(“We are out of the comment”)
SyntaxError: invalid syntax
and I get a syntex error, anybody have any tips?
Lessons are pretty straight forward.
wtf
print("hi")
print("how are you")
print("i am happy that i learned how to use some code of python language")
print("very nice tutorial")
print("^_^")
Simple since now <3
These seem a little pointless. Just saying.
For person below this comment.. It might be because you have not used double quotes (" .. ") inside your print() function
When I input this example into IDLE, it returns:
SyntaxError: multiple statements found while compiling a single statement
What’s going on?
Try this print(‘"Is n\’t it", he said.’)
Continue this course!
I don`t understand what is the function # and what are the commas, I filled in same code of second into test code but that doesn`t work
wonderful tutorial
great tutorial. I guess I will see the importance of this as I go on. for now, I don’t know.
I think i will get benefit of this work thanks
This second step is very helpful to understand the how to make a comment which is very necessary in programming.
Thanks. Great Tutorial……….
What about longer comments?
excellent well organised and very clear web tutorial
Quotes without space!!!
great tutorial
much easy than lisp.
Thanks for the tutorial
Ready for next tutorial!!
doable sofare..
Thanks for the tutorials!
i’m still not understand about "multiple line comments", can someone help me? Thanks
#comment
”’
this is also
a comment
”’