Comments are notes about the code that can explain the code to you or your fellow developers.
Comments are extremely important for you and for other people who will use your code. It is a good idea to get used to comment your code as soon as possible. When you will be working on someone else’s code, or even your own code after a long time, comments will save your life.
Single line comments
Python will ignore comments. In Python you can use hash mark (#) syntax for single line comments
1 2 |
# this is a single line comment print("I am printing a message") #this is another comment |
Multi-line comments
Python doesn’t have multi-line comments so to write a multiline comment in Python we just need to place a hash before each line.
One easy way to use multiline comment could be to place a message inside a triple quotes (“””) block. However, Python will treat it as we a string literal rather than a comment. Python ignore string literal messages (explained in another topic).
1 2 3 4 5 |
""" This could be treated as a multi-line comment message. Look we can write multiple lines and python would ignore it. Give it a try yourself. """ |