Go语言的字符串类型string
在本质上就与其他语言的字符串类型不同:
即:一个Go语言字符串是一个任意字节的常量序列。
Golang的双引号和反引号都可用于表示一个常量字符串,不同在于:
而单引号则用于表示Golang的一个特殊类型:rune
,类似其他语言的byte
但又不完全一样,是指:码点字面量(Unicode code point),不做任何转义的原始内容。
There are two forms: raw string literals and interpreted string literals.
foo
.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 may 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 values in various formats.
=
根据我找到的资料以及碰到的情况来看, Go语言的单引号一般用来表示「rune literal」 ,即——码点字面量。