Open In App

How to write Comments in Python3?

Last Updated : 07 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Comments are text notes added to the program to provide explanatory information about the source code. They are used in a programming language to document the program and remind programmers of what tricky things they just did with the code and also help the later generation for understanding and maintenance of code. The compiler considers these as non-executable statements. Since comments do not execute, when you run a program you will not see any indication of the comment in the output.

Syntax: The hash(#) symbol denotes the starting of a comment in Python.  

# This is a comment in Python

Example:

python
# This is the syntax of a comment in Python
print("GFG")

# Comments dont have any effect on the interpreter / output

Output :  

GFG

Comments should be made at the same indent as the code it is commenting on.

python
def GFG():
  
  # Since, this comment is inside a function
  # It would have indent same as the function body
  print("GeeksforGeeks")
  
  for i in range(1, 2):

    # Be careful of indentation
    # This comment is inside the body of for loop
    print("Welcome to Comments in Python")
  
# This comment is again outside the body
# of function so it wont have any indent.

print("Hello !!")
GFG()

Output
Hello!!
GeeksforGeeks
Welcome to Comments in Python

Types of Comments

1. Single-Line Comments: Comments starting with a ‘#’ and whitespace are called single-line comments in Python. These comments can only stretch to a single line and are the only way for comments in Python. e.g.

# This a single line comment.

2. Multi-line (Block) comments: Unlike other programming languages Python doesn’t support multi-line comment blocks out of the box. However we can use consecutive # single-line comments to comment out multiple lines of code. Some examples of block comments-

# This type of comments can serve
# both as a single-line as well
# as multi-line (block) in Python.

3. Inline Style comments: Inline comments occur on the same line of a statement, following the code itself. Generally, inline comments look like this:

x = 3        # This is