What is the difference between backticks (``) and double quotes ("") in golang?

What is the difference between backticks (``) and double quotes ("") in golang?

+30
source share
4 answers

In quotation marks, ""you need to escape newlines, tabs, and other characters that do not need to be escaped in reverse checkmarks ''. If you put a line break in a line with a reverse tag, it will be interpreted as a character '\n', see https://golang.org/ref/spec#String_literals

Thus, if you say \nin the return line, it will be interpreted as a literal backslash and the character n.

+22
source

Return lines are analogs of a multi-line raw line in Python or Scala: r""" text """or in JavaScript

String.raw'Hi\u000A!'

They can

:

  1. ,

  2. .

+16

Raw - . ('\') , ('\ r') .

- ( "\ r", "\n",...)

: http://ispycode.com/GO/Strings/Raw-string-literals

+4

'' , "" - .

The value of the raw string literal (a string without interpretation) is a string consisting of characters without interpretation (implicitly in UTF-8 encoding) between quotation marks

Interpreted string literals are character sequences between double quotes, as in a "bar". Any character can appear in quotation marks, except for a new line and an unscreened double quote.

PS: the words in italics are mine

https://golang.org/ref/spec#String_literals

0
source

Source: https://habr.com/ru/post/1688103/


All Articles