Python Comment : Comment in Python

5 (100%) 1 vote

As programs get bigger and more complicated, they get more difficult to read. Formal
languages are dense, and it is often difficult to look at a piece of code and figure out what
it is doing, or why.

For this reason, it is a good idea to add notes to your programs to explain in natural language
what the program is doing. These notes are called comments, and they start with the # symbol:


# Compute the percentage of hour


You can also write the same things as follows in one line.

percentage=(minutes*100)/60   # Compute the percentage of hour


Points to be Noted

  • Everything from the # to the end of the line is ignored—it has no effect on the program.
  • Comments are most useful when they document non-obvious features of the code.
  • It is reasonable to assume that the reader can figure out what the code does;
  • It is much more useful to explain why.
  • Good variable names can reduce the need for comments, but long names can make complex
    expressions hard to read, so there is a trade off.

Useless Comment

v=15   # Assign 15 value to test

Useful Comment

v=15   # Velocity in meters/second


For any query or issue, feel free to discuss on

Satya Prakash

VOIP Expert: More than 8 years of experience in Asterisk Development and Call Center operation Management. Unique Combination of Skill Set as IT, Analytics and operation management.

Leave a Reply

%d bloggers like this: