How to Write Single Line Comment Block in Python

Comments in Python are helpful while you are testing your code. The compiler ignores the commented code; hence we can experiment with the code as much as possible. With comments, we can better understand our code, make it more readable, and help team members know how it works.

Python single-line comment block

To write a single-line comment in Python, prepend the code with the hash symbol(#). Any code line starting with # in Python is regaled as a comment, and the compiler ignores it.

# print("Hello world")

print("The above statement is not printed because of single-line comment")

Output

The above statement is not printed because of single-line comment

In the above example, we wrote a single-line comment using # and then printed the “hello world” statement, but due to #, it did not print since the compiler ignores the code after #.

That’s it.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.