Skip to Content

Advertisement

You (Level 0)
0% Complete
Last Badge Earned
None

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.

Example print("Not a comment")
#print("Am a comment")
Result

Not a comment

Multiple Line Comments

Multiple line comments are slightly different. Simply use 3 single quotes before and after the part you want commented.

Example '''
print("We are in a comment")
print ("We are still in a comment")
'''
print("We are out of the comment")
Result

We are out of the comment

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.

For a more tangible and better look into the Python language, consider reading the following book. It's an excellent read.

Your code will execute in this window.



Let's explore some more tutorials or topics!

Next Tutorial Previous Tutorial

Advertisement

If you enjoyed this resource, support me by sharing this page with others.

Comment on

Show Comments
  • User

    keith the wilderbeast Nov. 6, 2017, 12:08 p.m.

    im keith and whats wrong with it

  • User

    Ma nan Oct. 30, 2017, 11:54 a.m.

    I like anal beads up my ass, OH YEA

  • User

    LOLOLOLOLOLOLOOLOLOL Oct. 30, 2017, 11:48 a.m.

    anal beeds

  • User

    Jagvir Kahlon July 4, 2017, 12:44 p.m.

    hi

  • User

    Rawr xD March 30, 2017, 10:51 a.m.

    Porn! Is good! For your sexual desires!

  • User

    Rawr xD March 30, 2017, 10:51 a.m.

    Porn! Is good! For your sexual desires!

  • User

    Rawr xD March 30, 2017, 10:51 a.m.

    Porn! Is good! For your sexual desires!

  • User

    Rawr xD March 30, 2017, 10:50 a.m.

    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!!

  • User

    Rawr xD March 30, 2017, 10:50 a.m.

    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!!

  • User

    Rawr xD March 30, 2017, 10:50 a.m.

    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!!

  • User

    Rawr xD March 30, 2017, 10:50 a.m.

    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!!

  • User

    Annie Zhu Jan. 19, 2017, 12:24 a.m.

    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")

  • User

    Annie Zhu Jan. 19, 2017, 12:24 a.m.

    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")

  • User

    Annie Zhu Jan. 19, 2017, 12:23 a.m.

    print("not a comment") #print("Am aa comment")

  • User

    Annie Zhu Jan. 19, 2017, 12:22 a.m.

    print("not a comment") #print("Am aa comment")

  • User

    mindwars Jan. 13, 2017, 1:23 a.m.

    not sure what a comment is

  • User

    Whizkid11189 Nov. 20, 2016, 8:16 p.m.

    print "testing"

  • User

    aonomike Nov. 11, 2016, 9:18 a.m.

    #test plan

  • User

    osteocoder Nov. 9, 2015, 1:22 p.m.

    print("Me:)#oh my

  • User

    Myshadow Oct. 24, 2015, 9:26 p.m.

    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?

  • User

    Zersiax July 21, 2015, 10:33 p.m.

    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 :)

  • User

    Subwwoofer May 12, 2015, 6:42 a.m.

    ''' print ("We are in a comment") print ("We are still in a comment") ''' print ("we are out of the comment")

  • User

    3thos May 5, 2015, 6:26 a.m.

    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") ''' '\nprint("We are in a comment")\nprint ("We are still in a comment")\n' >>>

  • User

    mike426 May 3, 2015, 12:20 a.m.

    # is hash sign and not pound £ sign?

  • User

    Kola April 23, 2015, 8:31 a.m.

    ''' print("We are in a comment") print("We are still in a comment") ''' displayed this '\nprint ("We are in a comment") \nprint ("We are still in a comment") \n' while print("We are out of the comment") print the comment separately. why not together?

  • User

    swalvatne April 12, 2015, 6:20 p.m.

    ""print("We are in a comment!")

  • User

    jerohero March 3, 2015, 2:01 p.m.

    print ("im happy")

  • User

    Dan Feb. 26, 2015, 7:10 a.m.

    #comments are important ''' multilple line comments are even more important when there is a lot to say '''

  • User

    PapaJack Jan. 4, 2015, 10:16 p.m.

    The code simulator on this page doesn't recognize blank lines,\n or tab \t or print(' '). ''' Show 2 blank lines before printing to the console "Two Blank Lines" ''' print("\n\nTwo Blank Lines")

  • User

    lastone2survive Dec. 19, 2014, 9:01 p.m.

    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") '\n\nprint("We are in a comment")\nprint ("We are still in a comment")\n'

  • User

    lastone2survive Dec. 19, 2014, 8:39 p.m.

    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?

  • User

    Bow-Tech Dec. 18, 2014, 12:56 a.m.

    Lessons are pretty straight forward.

  • User

    chris anderson Nov. 28, 2014, 3:06 p.m.

    wtf

  • User

    abdullah anisetty June 29, 2014, 9:02 a.m.

    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("^_^")

  • User

    Bob Evans May 28, 2014, 12:19 p.m.

    These seem a little pointless. Just saying.

  • User

    Gaurav Kulkarni May 22, 2014, 10:11 p.m.

    For person below this comment.. It might be because you have not used double quotes (" .. ") inside your print() function

  • User

    Francie May 18, 2014, 8:18 a.m.

    When I input this example into IDLE, it returns: SyntaxError: multiple statements found while compiling a single statement What's going on?

  • User

    Nishantha May 1, 2014, 6:31 a.m.

    Try this print('"Is n\'t it", he said.')

  • User

    MrCirca April 14, 2014, 3:01 p.m.

    Continue this course!

  • User

    whdqh1550 April 14, 2014, 1:46 p.m.

    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

  • User

    Naren April 8, 2014, 3:20 a.m.

    wonderful tutorial

  • User

    Freezeal March 31, 2014, 1:32 p.m.

    great tutorial. I guess I will see the importance of this as I go on. for now, I don't know.

  • User

    marwaniz March 23, 2014, 6:07 a.m.

    I think i will get benefit of this work thanks

  • User

    Lotfi GHAZOUANI Feb. 25, 2014, 12:43 p.m.

    This second step is very helpful to understand the how to make a comment which is very necessary in programming.

  • User

    webspiderls Feb. 1, 2014, 6:45 a.m.

    Thanks. Great Tutorial..........

  • User

    Joshua Tsai Jan. 6, 2014, 3:14 p.m.

    What about longer comments?

  • User

    richard Dec. 29, 2013, 1:37 p.m.

    excellent well organised and very clear web tutorial

  • User

    Pyn00b Dec. 24, 2013, 8:51 a.m.

    Quotes without space!!! great tutorial



Advertisement