Comments

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

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

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.

If you enjoyed this resource, support me by sharing this page with others.
Share on Facebook
Facebook
Share on Google+
Google+
Share on StumbleUpon
StumbleUpon
Digg this
Digg
Tweet about this on Twitter
Twitter
Share on Reddit
Reddit

Leave a Comment

  1. I dont understand what is the function # and what are the commas, I filled in same code of second into test code but that doesnt work

  2. When I input this example into IDLE, it returns:

    SyntaxError: multiple statements found while compiling a single statement

    What’s going on?

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

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

  5. 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?

  6. 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”)

  7. 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”)

  8. ”’
    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?

  9. 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”)

    >>>

  10. ”’
    print (“We are in a comment”)
    print (“We are still in a comment”)
    ”’
    print (“we are out of the comment”)

  11. 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 🙂

  12. 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?

  13. 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”)

  14. 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”)

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

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

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

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

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.