Remember the code from the last article

package main

import "fmt"

func main(a) {
   fmt.Println("Hello, World!")}Copy the code

The go language differs from the Java language in that it can be directly compiled into an executable file, called an EXE, just like the C language.

This will be very convenient for us

go build hello.go

The command generates an executable binary file called Hello, which we can then run anytime, anywhere, without any recompilation or other operations.

Package the main?

Just like libraries, or modules, in other languages, Go organizes code through packages. There are multiple GO files in a package, each of which starts with a package statement.

import

Just like Python, we can use import methods to call methods written by others (or by ourselves, of course).

The GO library provides many packages, such as input-output sorting and text processing. The specific package will be introduced in the following article.

Not only can we not import insufficient packages, we can’t import too many packages (perhaps to ease the reading burden), so we can only import packages that are used.

Like Python, the go language does not require semicolons, but you can write multiple statements on a single line using semicolons.

Because the compiler actively converts the newline after a particular symbol to a component number during compilation, the placement of the newline can affect the correct parsing of the GO code.

Special symbol refers to

  • identifier
  • Integer, floating point, imaginary, character, string
  • Keyword: Break continue fallthrough return
  • Operator and ++ –)]}

In a way, it’s a good thing that code specifications are unified

This article is participating in Golang Theme Learning Month! Event, click to view details of the event