python-comments

Introduction to Python Comments Concept

In this article you will learn some basic topics of Python Comments.

Python Comments- Before moving ahead let’s know a little bit about Python.

IntroductionPython is open-source and free programming language. It is easy to use and learn as compared to other languages like C ++, Java, C# and JavaScript. It is highly recommended and allows itself to get integrated with other languages like C ++, C#, etc., One of the most important key factors of Python is it is Object-Oriented Language and had been used by many giant companies for so many purposes such as handling file data, web app, Desktop application, Machine learning and so on.

Python Comments – One of the most useful functions of Python is Python comments which allows programmers to write comments while writing codes by using sign (Hash- (#)). In the starting of the line use sign (#) and write your line and it will be rendered or read as comment and not considered as code by Python. There’s no limit of comments in Python, as a programmer you can write as many you want.

Why should use comments in Python – A Comment in Python defined as writing a rough line of code or statement to make the code more readable and understable. In other words, Comments can be used to prevent execution while testing code.      

Creating a Comment

# Hello programming world.
python-comments
As it is shown clearly that statement is not printed

To define code or make it more readable, Comments can be used at the end of the line, but Python will not consider as Comment line.

print("Hello!") # It will not stop Python from executing code.
print('codingstreets.') # It will not stop Python from executing code.
python-comments
As statement is written with sign (#) but at the end of the line, therefore code will execute or print.

A comment is not mandatory to be text line, it can be itself a code in Python

#print('Hello World')
print('This is not a comment')
#print('This is a comment')
python-comments

As it is shown clearly that comments line not executed and only code line executed.

Multi Line Comments Multi-line comments are defined as writing more than one line of statement.In Python, multi-lines comments can be written with two types, either adding sign (#) in starting of each line or write your statement inside Triple Quotes (“””).   

Write multi-line comments by adding sign (#) in starting of each line.

Example –

 # As a beginner I should learn Python.
# I like to learn computer programs.
# Hello programming world.
python-comments

As statement is written with sign (#) so none of these statements will execute or print.

Write multi-line comments by placing statement inside Triple Quotes (“””).

python-comments

As statement is written with Triple Quotes (“””) therefore none of these statements will execute. Only print statement will be printed because not written with Triple Quotes (“””).

If you find anything incorrect in above discussed topic and have any further question, please comment down below.

Follow us on

Recent Post

Popular Post

Top Articles

Archives
Categories

Share on