Lesson2

Comments

The Python Comments tutorial explains how to use comments with Python.

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

1 2

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

1 2 3 4 5

''' 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.

Try testing your code with the code simulator!


Comments

comments powered by Disqus