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.
v=15 # Assign 15 value to test
v=15 # Velocity in meters/second
- 57A sample Program #!/usr/bin/python print "Hello, Python!"; Outupt: Executing the program.... $python2.7 main.py 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…
- 55Python 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…
- 43Welcome 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…
- 35Operators 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…