[Tutor] Comment

Richard Damon Richard at Damon-Family.org
Fri Aug 23 19:19:05 EDT 2019


On 8/23/19 7:13 PM, Cameron Simpson wrote:
> On 23Aug2019 22:36, Olsen, Avalow Y
> <Yuanyuan.A.Olsen at HealthPartners.Com> wrote:
>> Is there a mechanism to comment out large blocks of Python code? So
>> far, the only ways I can see of commenting out code are to either
>> start every line with a #, or to enclose the code in triple quotes.
>
> I sometimes put the code in an "if False:" statement.
>
> There isn't a multiline comment syntax, so you need to either comment
> out individual lines or use a multiple contruct (eg the "if"
> statement) or your suggestion of the triple quoted string (though that
> breaks as soon as the enclosed code itself has such a string).
>
> Cheers,
> Cameron Simpson <cs at cskk.id.au> 

You can get around almost all of the triple quote issues by always using
one style of triple quotes in your code (like always use """   """)
except for commenting out blocks, those use the other form of quotes
(''' ''')

Unless you actually have strings that contain 3 quotes of the same type
in a row, this works.

-- 
Richard Damon



More information about the Tutor mailing list