View on GitHub

python-for-kids

Learning and exercise content on Python for Kids

Day 15 - Commenting on Code

As a developer you write many logic and think many different approaches. As one problem can be solved in couple of different ways we might want to document what we are doing in terms of the flow of our code. This is not only helpful for others who are reading and modifying our codes but also sometimes for us too. Because we might forget certain approach that we have taken years or months ago. So writing a note is important. This is known as comment. Comments are the lines or texts which is ignored by the compliler when we execute our code. In all programming language comment is a common practice and differs a bit depending on each varity. Let’s see how it looks like in Python.

Single line comment

# below will print the "Hello"
print("Hello")

Single line in-line comment

In the same line where the executation code is written

# Same line comment anything after # in that will be ignored
print("Hi") # This will print "Hi"

Multiline comment

# Line 1 comment
# Line 2 comment
# Line 3 Comment
print("multiline comment")

Another way to comment multiline is

""" This another example
of multiline comment
which does not require # to be repeated"""

print("Multiline with three double quotes")

Day 15 - Exercise

  1. Comment your previously written code and run it to check if they are working fine.

Next: Day 16 - Working with Inputs

Back to Index