Python Tutorial 2-Comments

Comments are used to block out something entered into your code that should not interact with your program. Comments are common in all programming languages and can be used to add developer information, code explanation, or to help troubleshoot problems within code.

Python comments are a little different than other languages but are pretty easy to get used to. There are 2 types of comments:

The # symbol is used to comment out single lines while placing ‘ ‘ ‘ before and after a block of lines will comment all lines in between them out.

Single Line

Multi Line

Until now you were able to input everything using IDLE, but if you attempted the second example you received an error. Python will not accept multiple statements in IDLE. You will get an error stating SyntaxError: multiple statements found while compiling a single statement

To resolve that you need to use the Python Shell to write anything with more than 1 statement, or you need to enter 1 statement at a time, which defeats the idea of using the second comment method. To open the Python Shell from IDLE go to File>New File. Type your statements into the shell and then save it. You can name it whatever you want but make sure it has the .py extension at the end. Then from the same shell window go to Run>Run Module and you will see the results in IDLE.

That’s it for comments…pretty easy right. Well don’t get all excited and start bragging to your friends that you are a Python Guru because it gets harder from here. Oh wait, you’re a programmer…you have no friends. Just kidding..until next time.