This is a creation in Article, where the information may have evolved or changed.
go语言是一门静态类型的开发语言
Features of the Go language:
- Automatic garbage collection
- Richer built-in types
- function multiple return value
- Error handling
- Anonymous functions and closures
- Types and Interfaces
- Concurrent programming
- Reflection
- Language interactivity
New data types in the Go language
- Dictionary type (map)
- Array slices (Slice). You can think of an array slice as an array that can grow dynamically.
First GO Program
// go1 project main.gopackage mainimport ( "fmt")func main() { fmt.Println("Hello, world. 你好,世界! ")}
Print effect
The start of each go source file is a package declaration that represents the packages to which the go code belongs. The package is the most basic distribution unit in the Go language, and is also the embodiment of the dependency relationship in engineering management. To build the go executable, you must create a package with the name main and include a function called main () in the package, which is the starting point for the go executable.
The main () function of the go language cannot have parameters, nor can it define return values.
Import statement for importing packages on which the program depends
Go function
func 函数名(参数列表)(返回值列表) {// 函数体}
Support for multiple return values:
As follows: Supports two return values
funcintfloat64float64, err error) {// 函数体}
One is called result and the other is err. Not all return values must be assigned a value. Return values that are not explicitly assigned when the function returns are set to the default values, such as result is set to 0.0, and err is set to nil.
Go Comment mode
1. Block Comment:
/*块注释*/
2. Line Comment:
//行注释
The Go program does not require the developer to add a semicolon after each statement to indicate the end of the statement