Comments in python

 Comments in python

    • Comments are described as parts of the code.
    • Provide facilities for the understanding of programmers, developers.
    • Single line comments: -
    • Use the hash # mark before the desired comment:
# This is a comment
    • Python ignores everything after the hash mark and up to the end of the line.
    • We can insert Comments anywhere in the code.
Ex.
print("This will run.")  # This won't run
 
Example
"""
This is a comment
written in
more than just one line
"""
print("Hello, World!")

    • Python doesn’t support multiline comments as in other languages such as CJava, and Go, But we can add a multiline string (triple quotes) (“ ” ”)in our code.
    • The triple quotes appear right after the function, method, or class definition as docstrings (documentation strings). 
    • Docstrings can be accessed using the __doc__ attribute.
================================================ 

Post a Comment

0 Comments