In python, we use backslash to indicate that the current statement continues to next line
for example,
a = b + c + s \
+ x + y
or simply,
a = b + c + s +
x + y
Is it possible to do that in Go language? Thanks
Multiline strings Creating a multiline string in Go is actually incredibly easy. Simply use the backtick ( ` ) character when declaring or assigning your string value. str := `This is a multiline string.
For example, n = 50 is an assignment statement. Multi-Line Statements: Statements in Python can be extended to one or more lines using parentheses (), braces {}, square brackets [], semi-colon (;), continuation character slash (\).
What you do put your cursor where you want to add a character on a line, then use SHIFT+ALT and either the arrow keys or your mouse (you have to click to the same column position the line that you are selecting to) to select all the lines that you want to edit the same way.
PythonServer Side ProgrammingProgramming. Statements in Python typically end with a new line. Python does, however, allow the use of the line continuation character (\) to denote that the line should continue. For example − total = item_one + \ item_two + \ item_three.
Sure it is, just put an operator at the end, for example:
a = b + c + s + x + y
Also note that it's not possible to break the line before the operator. The following code is invalid:
a = b + c + s + x + y
The rule is described here and in the specification.
Interestingly, the the Go language specification itself requires semicolons at the end of each statement, but the lexer will insert implicit semicolons at the end of lines that look like statements immediately before compilation.
Therefore, to prevent the unwanted semicolon at the end of an unfinished line, all you need to do is ensure that the line doesn't end with something that could make it look like a complete statement.
In other words, avoid ending an incomplete line in a variable, constant, function, keyword, or postfix operator (e.g. ++
).
What does that leave? Well, a few things come to mind -- an infix operator (e.g. =
or +
), a comma, or an opening paren or brace or bracket, for example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With