GoConqr has a new look! Let us know what you think.

Module 3 of 3 · Text

Key takeaways

David Khieu

Key takeaways

  1. Comments can be used to leave additional information in code. They are omitted at runtime. The information left in source code is addressed to human readers. In Python, a comment is a piece of text that begins with #. The comment extends to the end of the line. 
  2. If you want to place a comment that spans several lines, you need to place # in front of them all. Moreover, you can use a comment to mark a piece of code that is not needed at the moment (see the last line of the snippet below), e.g.;
    # This program prints
    # an introduction to the screen.
    print("Hello!") # Invoking the print() function
    # print("I'm Python.")
  3. Whenever possible and justified, you should give self-commenting names to variables, e.g., if you're using two variables to store a length and width of something, the variable names length and width may be a better choice than myvar1 and myvar2
  4. It's important to use comments to make programs easier to understand, and to use readable and meaningful variable names in code. However, it's equally important not to use variable names that are confusing, or leave comments that contain wrong or incorrect information!
  5. Comments can be important when you are reading your own code after some time (trust us, developers do forget what their own code does), and when others are reading your code (can help them understand what your programs do an how they do it more quickly).

Exercise 1

What is the output of the following snippet?

# print("String #1")
print("String #2")

String #2

Exercise 2

What will happen when you run the following code?

# This is a multiline comment.
#
print("Hello!")

Instructions

You must submit an attempt for this quiz to progress. You can submit it after the last question.

Go to the chosen module

Feedback

What is it about?

What do you think of the new look?

How do you like it?