Comments in Python

(0 votes, average 0 out of 5)

Line Comments

Line comments in Python are very simple.  The # character denotes that everything afterward on that line is a comment.  

1
2
#here is a whole-line comment for some code
x = 3   #this comments code on the current line

 

Block Comments

Unfortunately, there is no specific syntax for block comments in python.  To comment a block of code, you must simply place a # before every line in the block of code you wish to comment.  Many Python IDE's, however, provide a simple way to comment out a block of code.  A tricky way of quickly block-commenting a large block of code is to prefix the block with if False: and then indent the block to be commented.  Just remember un-indent and delete the conditional afterward!


Partner Links:
Last Updated on Tuesday, 29 June 2010 12:34  
Related Articles

» How to Eliminate Ads in Firefox

I, like many people I know, end up releasing my latent anger issues on my computer after about 5 minutes of Facebook and MySpace ads. The tips in this article will provide a way to mitigate these ads in your everyday browsing.  Now, keep in mind that this solution is imperfect, so some websites will still have some ads that get through, and every one in a while you will have to block new adds manually (we'll touch on this in a bit). Here are a couple ways to drastically reduce the number...

» How to Get the Latest Version of a Program in Ubuntu

Ubuntu, the popular Linux distribution, is well-known for its stability. This stability is due in part to its 6-month release cycle. Main programs included with Ubuntu are only updated every 6 months. This ensures that the developers have adequate time to test the software for regressions, bugs, and instabilities. However, sometimes it is nice to install the latest version of a program. This tutorial will use the application launcher Kupfer (like Gnome Do or Launchy) but the same procedure...

» How to Enable Playback of MKV Files in Windows 7 Media Center

Back up your registry and create a system restore point. This is in case any problems arise in the process. the Windows 7 version of the codec pack. (The actual download is hosted by Major Geeks). When the download completes, install the codec pack.If you are running the 64-bit version of Windows 7, download and install those components as well. the MKV Registry Hack for your version of Windows 7 (32 or 64 bit).Double click the downloaded .reg file and allow the process to complete. This will...