Comment lines in Python

In this Python tutorial, we will discuss how to comment lines in python. Also, we will discuss:

  • Comment single line in python
  • Comment multiple lines python

Comment lines in Python

While programming in Python, we need to comment lines in Python.

Comment Single line python

In Python, the single-line comment starts with this ” # “ and it will ignore everything written with this. Comments are used to prevent the execution while testing code also comments are used to explain the code and it makes code more readable.

Example:

# Single line comment
a = 'Hello World'
print(a)

After writing the above code (comment Single line python). Here, you can see that before code I have used the ” # “ to comment that line. So in this way, comments work while working with code. You can refer to the below screenshot for comment Single line python.

Comment Single line python
Comment lines in Python

Comment multiple lines python

To comment multiple lines in python we will use this “#” and we have to comment every line individually, which is very monotonous.

Example:

# This is multiline comment
# Used for comment
# Every line in this way
a = 'Hello World'
print(a)

After writing the above code (comment multiple lines in python). Here, you can see that before code I have used the ” # “ to comment every line so this is the way to comment multiline in python. So in this way, comments work while working with code. You can refer to the below screenshot for comment multiple line python.

Comment multiple lines python
Comment multiple lines python

You may like following Python tutorials:

In this tutorial, we have seen how to comments lines in python. Also, we have discussed how to comment Single line and multiple comments in python.