Python #2 Comments in Python

 Comments in Python

Before you know, about comments in python first of all get ready with your text editor. For this series I will be using my favourite and famous Visual Studio Code.

Done!

Now before learning comments in python, lets first learn a simple basic command that every python developer knows on his/her first day.
Open a folder in Visual Studio Code to work in, click on file select open folder and now chose your personal folder.


Now create a main.py file in your folder, .py is the extension of your brand new python file. Main.py is the default name for python programs, same as index.html and style.css in HTML programming.


Lets learn our very first command in python that is print function. This is a built-in function by python that prints the text or string given inside the 2 quotation marks.


print("Comments in Python")



Ctrl + S to save this simple code. To run this click on green triangle at ribbon of Visual Studio Code.



As you can see our first python program successfully executed by Visual Studio Code and our code print("") prints the given code in the terminal of our text editor.



Now Lets, get to the topic to comments in python.
What are comments in python?
Comments are those commands or text that we don't want to execute to program but, want to show in our code. This is basically used for copyright our code from being stolen by anyone.


Now when you execute this program, it will just print Comments in Python not Hello World because it is commented out of the program.

There 2 ways to comment in python-
Single Line Comments
Multi Line Comments

Single line comments are comments done by hashing each line with looks kind of awkward and not a clean code.
 

# print("Hello World")
# print("Hello Yash")
# print("Hello India")
# print("Hello Python")
print("Comments in Python")



This is a way of multi line comments using just hashes. There is also a different for commenting multi lines in python by 2 sets of '''.


''' print("Hello World")
print("Hello Yash")
print("Hello India")
print("Hello Python") '''

print("Comments in Python")



This is also a way to do multi line comments in python with clean code manner.

Post a Comment

1 Comments