gotchagoCritical
What is the difference between backticks (``) & double quotes ("") in golang?
Viewed 0 times
doublequotesbackticksbetweenthedifferencegolangwhat
Problem
What is the difference between backticks (```
) & double quotes (""`) in golang?Solution
In quotes
"" you need to escape new lines, tabs, quotes and other characters that do not need to be escaped in backticks ```. If you put a line break in a backtick string, it is interpreted as a '\n' character, see https://golang.org/ref/spec#String_literals
Thus, if you say \n` in a backtick string, it will be interpreted as the literal backslash and character n.a := "\n" // This is one character, a line break.
b := `\n` // These are two characters, backslash followed by letter n.Code Snippets
a := "\n" // This is one character, a line break.
b := `\n` // These are two characters, backslash followed by letter n.Context
Stack Overflow Q#46917331, score: 159
Revisions (0)
No revisions yet.