Skip to content
Home » PYTHON JUMPSTART COURSE Section 1 – Introduction, Lesson 10 – Comments

PYTHON JUMPSTART COURSE Section 1 – Introduction, Lesson 10 – Comments

Spread the love

We often want to add some information to our code to make it clear and easy to understand. It can be a great time-saver for other programmers who read our code as well as for our future selves. After a few months or years we may no longer remember what the code was supposed to do. If we have this information, things get clear in no time. The additional information that we add to our code is called comments. Comments are ignored by the interpreter, they are just for us.

We introduce comments with a hash sign (#). Everything following # up to the end of the line is treated as comments.

We place comments either before the line they refer to or at the end of the line.

comment

Example:

There are no multiline comments in Python, unlike in many other languages.

But you can imitate them by using triple strings:

"""
This is a multiline string
but it can be treated as 
a multiline comment.
"""

print("hello")

You can also use triple single quotes. In the output the string is ignored, so it acts like a comment:

hello

QUIZ

1. We introduce comments with:
    A) a hash sign (#)
    B) an at sign (@)
    C) a double slash (//)
 
2. We place comments:
    A) after the line they refer to
    B) before the line they refer to
 
3. We can imitate multiline comments in Python by surrounding them with:
    A) ## and ##
    B) “”” and  “””
    C) /* and */
 

TRUE OR FALSE?

1) Comments are ignored by the interpreter.
2) Everything following # up to the end of the line is treated as a comment.

SOLUTION

QUIZ

1.We introduce comments with:
    A) a hash sign (#)
    B) an at sign (@)
    C) a double slash (//)
 
2. We place comments:
    A) after the line they refer to
    B) before the line they refer to
 
3. We can imitate multiline comments in Python by surrounding them with:
    A) ## and ##
    B) “”” and  “””
    C) /* and */
 

TRUE OR FALSE?

1) Comments are ignored by the interpreter.
True
2) Everything following # up to the end of the line is treated as a comment.
True

PROJECT

PROJECT SOLUTION


Spread the love

Leave a Reply