=start=
Search keywords:
Golang Single Quotes
Golang Double Quotes
Golang Back Quotes
Reference results:
The conclusion is written in the first: in the go language is not inclined to use single quotation marks to represent strings, use double quotation marks or anti-quotation marks as needed.
A go language string is a constant sequence of arbitrary bytes. The string type of the go language is inherently different from the string type of other languages. Java's string, C + + std::string, and Python3 's str type are all just fixed-width character sequences, while the go language string is a UTF-8-encoded, variable-width sequence of characters, each of which is represented by one or more bytes .
string literals in the go language are created using double or inverted quotation marks:
- Double quotation marks are used to create resolvable string literals (which support escaping, but cannot be used to refer to multiple lines);
- Anti-quotes are used to create native string literals , which may consist of multiple lines (no escape sequences are supported), and native string literals are used to write multiline messages, HTML, and regular expressions.
There is forms:raw string literals and interpreted string literals.
- Raw string literals is character sequences between back quotes, as in
foo
.
- Interpreted string literals is character sequences between double quotes, as in "bar".
A rune literal represents a Rune constant, an integer value identifying a Unicode code point. A Rune Literal is expressed as one or more characters enclosed in single quotes, as in ' x ' or ' \ n '. Within the quotes, any character could appear except newline and unescaped single quote. A Single quoted character represents the Unicode value of the character itself, while multi-character sequences beginning With a backslash encode the values in various formats.
=
According to the information I found and the situation I encountered, the single quotes of the go language are generally used to denote "rune literal" , the code point literal.
Reference Links:
- Https://golang.org/ref/spec#String_literals
- Https://golang.org/ref/spec#Rune_literals
- http://teapottable.com/blog/starting-out-with-go-lang/
=eof=
Single quotes, double quotes, and anti-quotes in the Go language