Python Comment : Comment in Python

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


Related Posts

  • 57
    A sample Program #!/usr/bin/python print "Hello, Python!"; Outupt: Executing the program.... $python2.7 Hello, Python! What is Python? Python is a general-purpose interpreted, interactive, object-oriented, and high-level programming language. It was created by Guido van Rossum during 1985- 1990. Like Perl, Python source code is also available under the GNU…
    Tags: python
  • 55
    Python is a very simple language, and has a very straightforward syntax. It encourages programmers to program without boilerplate (prepared) code. The simplest directive in Python is the "print" directive - it simply prints out a line (and also includes a newline, unlike in C). There are two major Python…
    Tags: python
  • 43
      Welcome to the Python Knowledge Base and Tutorial   Python : Overview : What is Python? Why learn Python? Feature of Python Basic Syntax Where to write python program? Check if python already installed Python : Installation on Windows and Simple Example How to install python in windows? Simple Example…
    Tags: python
  • 38
    Example:  #!/usr/bin/python x = True y = False print('x and y is',x and y) print('x or y is',x or y) print('not x is',not x) Output: x and y is False x or y is True not x is False Few more example: 1. if (five == 5) AND (two ==…
    Tags: program, comment, python
  • 35
    Operators are the constructs which can manipulate the value of operands. Consider the expression 4 + 5 = 9. Here, 4 and 5 are called operands and + is called operator. Types of Operator Python language supports the following types of operators. Python Arithmetic Operators Assume variable a holds 10…
    Tags: python, variable, assume

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

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

%d bloggers like this: