The string type of the go language is string
inherently different from the string types in other languages:
Java string, C + + std::string, and Python3 str type are all just fixed-width character sequences
The go language string is a UTF-8-encoded, variable-width sequence of characters, each of which is represented by one or more bytes
That is: A Go language string is a constant sequence of arbitrary bytes .
Golang's double and back quotes can be used to represent a constant string, except that:
Double quotation marks are used to create resolvable string literals (escaped, 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 multiple lines of messages, HTML, and regular expressions
The single quotation marks are used to denote a special type of Golang: rune
, like other languages, byte
but not exactly, refers to code point literals (Unicode code points), without any escaping of the original content.
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/