Comments in python
Comments in python can be used by the programmer to explain the program code. It is used to make the code more readable. They can be used while testing to prevent the program line from execution. A python comment must start with hash symbol (#).Comments can be placed anywhere in the program code.
Example :
Example :
#This is a comment.
print(" hello world ! ")
print(" hello world ! ")
Python does not have a syntax for multi line comment. we can use # symbol at the starting of ever comments on every line to write a multi line comment.
Example :
#This is
#a multi line
#comment
print(" hello world ! ")
#a multi line
#comment
print(" hello world ! ")
String literals for multi line comment
Even though there is no unique way to write multiline comments in Python, we know that the Python interpreter ignores the string literals that are not assigned to a variable.
So, we can even write a single-line comment as:
' ' ' This is a
Multi line Comment ' ' '
" " " This is also a
Multi line Comment " " "
Multi line Comment ' ' '
" " " This is also a
Multi line Comment " " "
The quotation character can either be ' or ".
Here, the multiline string isn't assigned to any variable, so it is ignored by the interpreter. Even though it is not technically a multiline comment, it can be used as one.
⇐Prev
Next⇒
Comments
Post a Comment