This forum is now read-only. Please use our new forums at

405 points
Submitted by
about 7 years ago

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.

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.

438 points
Submitted by
over 5 years ago

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! :-)

461 points
Submitted by
Alessandro Rosa
over 4 years ago

-2 votes


He understood that """triple quotes""" were used to include documentation within the code

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

531 points
Submitted by
about 7 years ago


Cdd687c294c9006a3281a19b3c28d7af?s=140&d=retro Unode about 7 years ago

I learned that triple quotes can be used for documentation elsewhere. I was referring to!/exercises/1 which points out that triple quotes can be used for block comenting.

Picture Daniel Chateau over 6 years ago

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.

8d304533e14751ca81cce27f550db8a1?s=140&d=retro curtis mcallister about 6 years ago

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.

A1fe898d7efbafb057076d0f82d555c5?s=140&d=retro Bryan R almost 6 years ago

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.

A1fe898d7efbafb057076d0f82d555c5?s=140&d=retro Bryan R almost 6 years ago

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.