Single quotes, double quotes, and anti-quotes in the Go language

Source: Internet
Author: User

=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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.