1

For multiline string value like below:

var_a = "This is a very very"\
"very long string that "\
"consists of 3 lines"

A comment can be added only on the last line. Example:

var_a = "This is a very very"\
"very long string that "\
"consists of 3 lines" #add comment here

Adding comment anywhere else is a syntax error.

Is there any way to add comment on the first line?

variable
  • 8,262
  • 9
  • 95
  • 215
  • 1
    Put parentheses around your strings and lose the backslashes. Then you can put a comment at the end of every line. – khelwood Jun 24 '20 at 19:51

2 Answers2

1

I recommend using parentheses instead of backslashes to split a statement across multiple lines. That will allow you to put comments on each line, and is less error-prone.

var_a = ("This is a very very " # comment 1
         "very long string that " # comment 2
         "consists of 3 lines") # comment 3
khelwood
  • 55,782
  • 14
  • 81
  • 108
-2

The short answer is no! Everything after '/' will result in a Syntax Error. There is no way around it, but what you can do is just comment 3 times for every line above the variable.

# This is line 1 comment
# This is line 2 comment
# This is line 3 comment 
var_a = "This is a very very"\
"very long string that "\
"consists of 3 lines"

Commenting is a really important practice for programmers and the best practice is to comment above the line of code.