How to comment a Block of Code in Python

Hi guys. How are you all? I hope you all are fine. Today in this tutorial we will learn about How to comment a Block of Code in Python. here i am giving yu some methods which will be useful to block a code in python. By using these methods you can easily comment out the line or multiple line. So without wasting your time lets learn about of this.

How to comment a Block of Code in Python

  1. Comment a Block of Code in Python

    to comment a Block of Code in Python just Use #. You can use # for to comment out the code. By using # you can comment a block of code in python. This will comment a single line of code. You have to just put the # at the starting of the line which you want to comment out. Lets learn this by given below example. I hope this will help you: #print("hi") #print("How are you?) print("Good morning") Output : Good morning

  2. How to comment a Block of Code in Python

    to comment a Block of Code in Python just Use triple quotes. By using triple quotes You can comment a Block of Code in Python. This method is used for to comment multiple lines in python. You can comment out multiple lines at a time by using triple quotes in python. YOu just have to put triple quotes at the starting of the line and at the ending of it. It will simply commment it out. So without wasting your time lets learn about of this: """print("hi") print("How are you?) """ print("Good morning") Output : Good morning

Method 1: Use #

You can use # for to comment out the code. By using # you can comment a block of code in python. This will comment a single line of code. You have to just put the # at the starting of the line which you want to comment out. Lets learn this by given below example. I hope this will help you:

#print("hi")
#print("How are you?)
print("Good morning")

Output :

Good morning

Method 2: Use triple quotes

By using triple quotes You can comment a Block of Code in Python. This method is used for to comment multiple lines in python. You can comment out multiple lines at a time by using triple quotes in python. YOu just have to put triple quotes at the starting of the line and at the ending of it. It will simply commment it out. So without wasting your time lets learn about of this:

"""print("hi")
print("How are you?)
"""
print("Good morning")

Output :

Good morning

Method 3: Use if false

You can use if false for to comment a Block of Code in Python. By using if false you can comment out the multiple lines at a time in python. You have to just write if false and it will comment out the lines you want to block. So lets learn this by given below example. I hope this will help you.

if False:    
    print("hi")
    print("How are you?")
print("Good morning")

Output :

Good morning

Conclusion

So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.

Also Read,

Siddharth

I am an Information Technology Engineer. I have Completed my MCA And I have 4 Year Plus Experience, I am a web developer with knowledge of multiple back-end platforms Like PHP, Node.js, Python and frontend JavaScript frameworks Like Angular, React, and Vue.

Leave a Comment