6
Reply

How do you write comments in python?

Dinesh Beniwal

Dinesh Beniwal

5y
2.1k
2
Reply

    As the following format

    1. Using #- single line comments
    2. Using “”” “”” - for multi line comments

    # is used for single line comments
    Example:

    1. #this line will not execute due to single line comment
    2. print("hello this will execute")

    ”””””” is used for multiline line comments
    Example:

    1. """This will not
    2. execute due to
    3. multiline comments"""
    4. '''Also this will not
    5. execute due to
    6. multiline comments '''
    7. print("hi")

    There are two ways to comment in the python

    • Single line Comments using Hash or Pound # Symbol
    • Multiline Comments Using Tripple Quote """ """

    Single Line Comments

    We can use Hash and pound symbol
    Example

    1. # This is single line comment
    2. print("Hello C# Corner") # This is python print function
    3. # End of the program

    Multiline comments

    We can use triple quotes
    Example

    1. """
    2. This
    3. is
    4. multiline comments
    5. """
    6. '''
    7. This
    8. is also
    9. multiline comments
    10. '''

    You can also use comments to define documantation of the program. For that you can use docstring

    Note
    To read more about about docstring click on the following link

    Python DocString

    using hash (#). # this is the comment

    Using # symbol you can comment any line in python

    using # for single line comment

    single line comment

    print(“Hello, python”)

    using triple quotes “”” for multiline comment
    “””
    This is my multi
    line comment
    “””