Comments:
In computer programming, a comment is a programmer-readable explanation or annotation in the source code of a program. They are added with the purpose of making the source code easier for humans to understand, and are generally ignored by compilers and interpreters.
The syntax of comments in various programming languages varies considerably.
Comments in Python:
Comments are used to make program more readable and to give basic understanding to program reader that what program does and from where it starts, where it ends, etc.
Syntax:
A comment in Python starts with the hash character, # , and extends to the end of the physical line. A hash character within a string value is not seen as a comment, though. To be precise, a comment can be written in three ways - entirely on its own line, next to a statement of code, and as a multi-line comment block.
Example:
-------------------------------------------------
import datetime
import random
def date():
#function displays date
def grn():
#Now try to understand what this function does and tell in comment.
-------------------------------------------------
WILL U BE ABLE TO UNDERSTAND, WHAT THAT PROGRAM DOES, NO?
NOW Understand ->
def grn():
#g - generate r - random n - number (This function generates random number)
So NOW Will u Able to Understand What this Function does?
How u understand about this program? ...... By Comment ->
# g - generate r - random n - number (This function generates random number)
this is comment, started with "#" tag.
In every programming language Comment syntax may be different, like in C/C++ it started with " // "
Types of Comments:
1) Single Line Comments:
We discussed above, is an example of Single Line Comment
2) Multiline Comments:
Multiline Comment is started with ''' (three apostrophe sign)
Multiline comment helps to write a Paragraph in our Programs
in singleline comment you can only write a note till that line ends
in multiline comment you can write a note till you close it again with again ''' (three apostrophe sign).
THANKS I hope YOU will get SOME Knowledge from this blog.
No comments:
Post a Comment