GO语言中的单引号、双引号、反引号

=Start=

搜索关键字:

golang single quotes
golang double quotes
golang back quotes

参考结果:

结论写在最前:在Go语言中不倾向于使用单引号来表示字符串,请根据需要使用双引号或反引号。

一个Go语言字符串是一个任意字节的常量序列。Go语言的字符串类型在本质上就与其他语言的字符串类型不同。Java的String、C++的std::string以及Python3的str类型都只是定宽字符序列,而Go语言的字符串是一个用UTF-8编码的变宽字符序列,它的每一个字符都用一个或多个字节表示。

Go语言中的字符串字面量使用 双引号 或 反引号 来创建:

双引号用来创建可解析的字符串字面量(支持转义,但不能用来引用多行);
反引号用来创建原生的字符串字面量,这些字符串可能由多行组成(不支持任何转义序列),原生的字符串字面量多用于书写多行消息、HTML以及正则表达式。
There are two forms: raw string literals and interpreted string literals.

Raw string literals are character sequences between back quotes, as in foo.
Interpreted string literals are 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 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」,即——码点字面量。

参考链接:

https://golang.org/ref/spec#String_literals
https://golang.org/ref/spec#Rune_literals
http://teapottable.com/blog/starting-out-with-go-lang/
=EOF=

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值