Also, you can conclude that you are able to write more than one line of comments without any problem because you used triple quotes. Output: Our course is for : Python programming languageĪs you see “Python programming language” has been printed and nothing has happened because you have added these comments and this is expected because, as it has been mentioned before, comments are totally ignored by the interpreter. Triple quotes """ are used to write these comments and most often these comments are written at the beginning of functions, modules, and classes.įor Example: """ Comments: Line 1 Line 2 Line 3 """ course = 'Python programming language' print('Our course is for : ', course)
?If you want to write another line, you have to put # again, or you can use triple quotes to write multi-line comment. In Python, we use the hash symbol to write a single-line comment.
PYTHON COMMENT CODE
Using comments in programs makes our code more understandable. You can understand from the result that the line, which starts with a hash sign, is totally ignored by the interpreter, and it works as a comment only. Python Comments Advantages of Using Comments. In order to write this comment, the line should start with the hash sign #.įor Example: # These variables refer to student name & age name = 'Huda' age = 25 print('name is :', name,', age is :', age) You can write this comment only in one line. In Python hash mark is used before the starting of the line of code to write a comment. They narrate the piece of code as required to explain the logic and program flow.
Mainly, Python supports two types of comments: Comments are written for the new developers who continue the project written by the other developers. So it’s going to be easier for them to read your code and understand what do you mean by each part of your code. Also, comments are useful when you want to share your program with other people. Be sure to use the right style for module, function, method docstrings and inline comments. From this meme, you can understand that if you come back to your code after one year, for example, it’s very hard to memorize what you have done and here comments come to the scene to remind you about what your code does.