0 points
Submitted by Unode
almost 10 years

Multiline comments don't actually exist in Python

As part of the Python course it is taught that in order to do a multiline comment one should use """triple quotes""". This is wrong. Python only has one way of doing comments and that is using #.

Triple quotes are treated as regular strings with the exception that they can span multiple lines. By regular strings I mean that if they are not assigned to a variable they will be immediately garbage collected as soon as that code executes. hence are not ignored by the interpreter in the same way that #a comment is.

The only exception to the garbage collection fact is when they are placed immediately after a function or class definition or on top of a module, in which case they are called docstrings and made available via the special variable myobj.__doc__.

Due to the existance of docstrings I’ve seen a lot of people confused about the use of """ elsewhere.

I suggest that the multiline comment lesson is removed or replaced with the instructions from the official PEP8 - Block comments section.

Answer 5397bb468c1ccc0d76000792

1 vote


Disappointingly the course has NOT been fixed and STILL, ONE YEAR LATER from the original comment above, teaches incorrect commenting. I also noted a module where the lesson showed comments using slashes “//“. Strange AND misleading!

They really need to update their backend testing system to use the latest builds so that NEW LEARNERS, who are likely using the latest build, will get consistent results and correct instruction.

So, although I am glad this is free to end-users, the quality should be improved - definitely after a YEAR.

Submitted by SpaceWalker0720
about 8 years

Answer 5594c69793767623c5000431

1 vote


Then Guido must be confused as well, though he did write the language….

Guido van Rossum ‏@gvanrossum 10 Sep 2011 @BSUCSClub Python tip: You can use multi-line strings as multi-line comments. Unless used as docstrings, they generate no code! :-)

Submitted by Alessandro Rosa
about 7 years

Answer 506070f30aef700002074bbe

-2 votes


He understood that “””triple quotes””” were used to include documentation within the code Ejm:

def x_intercept (m, b):
     "" "
     Return the x intercept of the line y = m * x + b. The x intercept of a
     line is the point at Which it crosses the x axis (y = 0).
     "" "
     return-b / m
Submitted by Davidnamy
almost 10 years


Unode almost 10 years

I learned that triple quotes can be used for documentation elsewhere. I was referring to http://www.codecademy.com/courses/introduction-to-python-6WeG3/2#!/exercises/1 which points out that triple quotes can be used for block comenting.

Daniel Chateau over 9 years

You are absolutely correct Unode. The lesson inappropriately refers to them as multi-line comments when they are in face NOT multi-line comments and do affect memory allocation in the interpreter.

curtis mcallister almost 9 years

this lesson is still in the python track. triple-quotes are definitely not comments. the interpreter will read them and you can assign them to a variable. that doesn’t sound like comment behavior.

Bryan R over 8 years

I also noticed this and was confused. As mentioned by those before me, This lesson should be removed or worked into a separate lesson for docstrings.

Bryan R over 8 years

okay, so I progressed to the next section and now I’m very confused.

when I type my comment with triple quotes in this comment lesson, it will print it on the console which is different from using the hash.

I got to the “subtraction” lesson and in that lesson the triple quotes are used to comment on the code. This comment does not print in the console so it seems that the triple quotes do work.

I like to poke around and test things out, so coded the same thing in both lessons and the output on the console was the same. There was a difference when I deleted everything except the comment though; it printed on the console in the “comment” lesson and did not print in the console in the “subtraction” lesson. Very odd; something is buggy or I don’t understand something.