Python Tutorials

Python Programs

Python Comments


Python Comments

In this tutorial, we will learn how to write comments in Python language. We will go through the different types of comments and how to use them in a program.


What are Comments

Comments are non-executable statements that are used to explain and document the code. They help improve the readability of the code and make it easier for others to understand. Comments can also be used to temporarily disable code during testing and debugging.


Syntax

The syntax to define comments in Python is:

# Single line comment
''' Multi-line comment
    continues here '''


Single line comments

  1. Single line comments in Python start with # and continue to the end of the line.
  2. They are used to add short explanations or notes within the code.

Python Program

print("Hello, World!")  # Print Hello, World! to the console

Output

Hello, World!


Multiline comments

  1. Multiline comments in Python start and end with triple quotes (''').
  2. They can span multiple lines and are used for longer explanations or to comment out blocks of code.

Python Program

''' Print Hello, World! to the console
    This is a multi-line comment '''
print("Hello, World!")

Output

Hello, World!