go language basics

silencement
Release: 2019-06-13 16:16:26
Original
4420 people have browsed it

go language basics

The most primitive language, from sign language used by humans, to speech expression; from English to Chinese, and to various programming languages ​​that computers can recognize, each language has its own grammar. Grammar is like an agreement between everyone, so that when communicating and synchronizing information, there is a communication standard, and accurate information can be conveyed to each other without problems caused by inconsistent mutual understanding. Then the Go language is similar. The basic grammar of Go language mainly consists of these aspects, Go language keywords, Go language identifiers, line separators and carriage returns, variable declarations separated by spaces, comments, and tags.

Go language keywords

1.1 Keywords and reserved words

Related to branch selection: switch, break, case, default, fallthrough

Conditional loop related: for, range, select, if, else, goto, continue

Type definition related: interface, struct

Multi-threading related: go, chan

Package management related: package, import

Variable definition related: map, const, type, var

1.2 Predefined identifier

Container operation related: append, cap, len,

Data type related: bool, byte, uint, uint16, uint32, uint64, int, int8, int16, int32, int64, float, float16, float32, float64, complex, complex64, complex128, string, uintptr

bool type value: true, false

Others: iota, real, recover, panic, nil, new, make, imag, copy, close

console output related: print, println

2 Go language variable identifier

cannot be a variable definition starting with a number, satisfying [ A-Z] and a combination of [a-z] and [0-9]. There can be no operators, no predefined identifiers, and no keywords. The following definition is illegal: (Illegal example)

starts with a number: 123var

Go language keywords cannot be used as variables, such as: case

operators cannot be used as Variable: max/total

3 Go language delimiter

line delimiter and space, line represents the beginning and end of a statement, equivalent to an instruction, no End with semicolon. But if there are multiple statements on the same line, semicolons are needed; to separate them.

4 Go language comments

mainly include single-line comments and multi-line comments as follows.

//Single-line comments

/*Multi-line comments*/

5 Go language tags

The tags of statements include : Keywords, identifiers, constants, strings, symbols.

Summary

So whether it is the languages ​​of various countries that humans communicate with, or the programming languages ​​that can convey information and instructions to computers. For those who want to master a language, mastering basic grammar is the first and necessary condition. As for how to quickly master the grammar and keep it in mind, especially for those who have no programming language foundation, the most effective and efficient way is to practice (write it) and use your hands more often to reach the level of application. So practice more, write more code, and read more code.

The above is the detailed content of go language basics. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
go
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template