Go language "Second article": Go syntax and data type

Source: Internet
Author: User

Go Language Basics Grammar

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.PrintIn("Hello, World!")

6 tags are (one per line):

1. fmt2. .3. PrintIn4. (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 the same as the other languages in the C family, ending with a semicolon, because all this work will be done automatically by the go compiler. If you intend to unload multiple statements on the same line, they must be used; it is considered a distinction, but we do not encourage this practice in actual development, the following two statements:

fmt.PrintIn("Hello, World!")fmt.PrintIn("菜鸟教程:runoob.com")

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), underscores _, but the first character must be a letter or an underscore and not a number. The following are valid identifiers:

mahes 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 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 | Caps | Close | Complex | complex64 | complex128 | UInt16
Copy | False | float32 | float64 | Imag | int | int8 | Int16 | UInt32
Int32 | Int64 | Iota | Len | Make | New | Nil | Panic | UInt64
Print | Printin | Real | Recover | string | true | UINT | uint8 | UIntPtr

Programs typically consist of keywords, constants, variables, operators, types, and functions, which may be used in programs such as parentheses (), brackets [], and curly braces {}; These punctuation marks may be used in programs:. 、,、;,: And ....

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

varint;

The appropriate use of spaces in the statement can make the program easy to read, no spaces:

fruit=apples+oranges;

By adding spaces between the face and operator, the program looks more beautiful, such as:

fruit = apples + oranges;
Go Language data type

In the Go programming language, data types are used to declare variables and functions. Data types occur in order to divide the data into the required memory size of the data, programming when the big data need to apply for large memory, you can make full use of memory. The go language has the following data types by Category:
Serial number | Type | Describe
|-|-|-|
| Boolean Type | The Boolean value can only be a constant true or false, such as: var b bool = true;|
| Number Types | shaping int and floating-point float32, Float64,go languages support shaping and floating-point numbers, and support complex numbers, where the operations of bits are complement-based; |
|3 | String Type | A string is a sequence of characters concatenated with fixed-length characters. The go string is concatenated by a single byte, and the Go language byte uses the UTF-8 encoding to identify Unicode text; |
|4 | Derived Types | Includes: (a) pointer type (Pointer), (b) array type, (c) structured type (struct), (d) channel type, (e) function type, (f) Type of slice, (g) interface type (interface), (h) map type;

Go language "Second article": Go syntax and data type

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.