Comments in Python

Comments Comments are useful for understanding and maintenance of the code.

Single line comments

The first line is ignored by Python and the second line prints the string.
# Single line comment
print('Hello world')

  • Comments in Python

In-line Comment

Comment is used to the right of the code.
print('Hello world') # comment in same line

Multiline comments

Python ignores the string if it is not assigned to a variable, this technique is used to define a multiline comment. There is no direct support for multiline comment in Python.

Use three single quotes or three double quotes to create one multiline comment. Here only the string Hello world is printed.
'''
First line comment 
Second line comment
third line comment
'''
print('Hello world')
Using three double quotes
"""
First line comment 
Second line comment
Third line comment
"""
print('Hello world')

docstring in python

For a function or class we use documentation to understand the details about it, though this is written like we write comment but those can be accessed.
def add_num(a,b):
    '''comment inside about the function'''
    return a+ b
print(add_num(4,5))
print(add_num.__doc__)
Output is here
9
comment inside about the function

Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com



    Post your comments , suggestion , error , requirements etc here





    Python Video Tutorials
    Python SQLite Video Tutorials
    Python MySQL Video Tutorials
    Python Tkinter Video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2021 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer