Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Place comments inside a multi-line list literal

Tags:

People also ask

How do you comment a list in Python?

A comment in Python starts with the hash character, # , and extends to the end of the physical line. A hash character within a string value is not seen as a comment, though. To be precise, a comment can be written in three ways - entirely on its own line, next to a statement of code, and as a multi-line comment block.

How do you comment multiple lines in C++?

You can comment out one or more lines of code in any C/C++ editor view. The leading characters // are added to the beginning of each line when commenting one or more lines of code. You can also block comment multiple lines of code using the characters /* */ .


I am doing an optimization problem and writing a gigantic list. I would like to insert comments inside the list like below

my_rhs = [1.0, 1.0, 0.0, 0.0, 0.0,\ #comment1
         -1.0, -1.0, -1.0,\ #comment2
          0.0, 0.0, 0.0]

but when I do this Python gives an error. How can I comment in the places shown? I tried defining each line as a new list and using + to append but that doesn't seem to work either. Like below

my_rhs = [1.0, 1.0, 0.0, 0.0, 0.0]+\ #comment1
         [-1.0, -1.0, -1.0]+\ #comment2
         [0.0, 0.0, 0.0]

How can I comment in the shown locations without Python giving an error?