In this tutorial of the Python Tutorial Series at blog.codersty.com, I would like to talk to you in the abaout comment line. Although comment lines and description lines seem simple, they are important for developers. Let’s get started.
What is Comment Line ?
Readability, which is an important issue in the software world, is also a very important place in the comment line and description lines. It is a magic wand that allows us to understand someone else’s code or to understand someone else’s code. Especially when you work in a company or when you are in a big project, you will deal with thousands of lines of code. Sometimes you may not even remember to look back at your own code. Here we are developers to solve this problem by writing small notes or explanations in the code we are eliminating this problem.
Using Python Comment Line
It is very simple to use Python recognizes the lines that it sees as
# comment lines and does not process them. Let’s show with an example immediately.
#We have created a variable named txt txt = "Python Tutorials for blog.codersty.com" #We printed the variable text on the screen print (txt)
What if I have to add more than one line to the code ? Do I have to put the # sign on each line, of course, no, if you want to add more than one comment line to the code, just type it in three quotes. Python again recognizes it as a comment line and does not process it. Let’s illustrate with an example.
""" program that adds two numbers """ number1 =5 number2 =4 result = number1+number2 print("Result is :",result)
As you can see, the description lines are different in color. Also, as it appears in your output, Python has again recognized it as a comment line.
Will the comment line and comment lines we add slow down our code? Of course, no comment lines you add to your code will slow down our program. Also, the small notes you add to our codes make you a better developer. As you move along this path, you will find that it is important not only to write code, but also to write legible code so that you can think that writing is an art 🙂