Go Language Basics

Source: Internet
Author: User

Go tag

The Go program can consist of multiple tags, which can be keywords, identifiers, constants, strings, and symbols. The following GO statement consists of 6 tokens:

FMT.  Println("Hello, world!" )

6 tokens are (one per line):

1 . FMT 2 . . 3 . Println4. (5"Hello, world! " 6.)
Row delimiter

In the Go program, a line represents the end of a statement. Each statement does not need to be semicolon-like other languages in the C family; End, because all of this work will be done automatically by the Go compiler.

If you intend to write multiple statements on the same line, they must be used; , but we do not encourage this practice in practical development.

The following are two statements:

Fmt. Println ("Hello, world! " ) fmt. Println ("666666666666666666")
Comments

Comments are not compiled, and each package should have related comments.

Single-line comments are the most common form of annotation, and you can use a single-line comment at any point, starting with//. Multiline comments are also called block annotations, which begin with/* and end with */. Such as:

// single-line comment /* */
Identifier

Identifiers are used to name program entities such as variables, types, and so on. An identifier is actually a sequence of one or more letters (A~Z and A~z) numbers (0~9) and underscores _, but the first character must be a letter or an underscore and not a number.

The following are valid identifiers:

MAHESH  KUMAR  ABC  move_name a_123myname50  _temp  J  a23b9 RetVal

The following are invalid identifiers:

1ab (starting with a number)  Case (keywords for Go language) a+b (operator is not allowed)
Key words

Here are the 25 keywords or reserved words that will be used in the Go code:

Break Default Func Interface Select
Case Defer Go Map struct
Chan Else Goto Package Switch
Const Fallthrough If Range Type
Continue For Import Return Var

In addition to the keywords described above, the Go language also has 36 predefined identifiers:

Append bool Byte Cap Close Complex Complex64 complex128 UInt16
Copy False Float32 Float64 Imag Int int8 Int16 UInt32
Int32 Int64 Iota Len Make New Nil Panic UInt64
Print println Real Recover String True UInt Uint8 UIntPtr

Programs are typically made up of keywords, constants, variables, operators, types, and functions.

These delimiters may be used in the program: parentheses (), brackets [], and curly braces {}.

These punctuation marks may be used in the program:. 、,、;,: And ....

The space of the Go language

The declaration of a variable in the Go language must be separated by a space, such as:

var int;

The proper use of spaces in a statement can make the program read easily.

No spaces:

Fruit=apples+oranges;

By adding spaces between variables and operators, the program looks more beautiful, such as:

GOFMT format code can be used in Go tools

Go Language Basics

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.