GO language grammar structure

GO language structure

  1. package declaration
  2. Import package
  3. function
  4. variable
  5. statement && expression
  6. Comment
package main
import "fmt"
func  main() {
	fmt.Println("Hello,World!")
}

For example, this code block is explained line by line according to the above syntax structure.

The first line of package main defines a package name. The first non-commented line in the source file must indicate which package this file belongs to. For example, package main can represent an independently executed program. Each GO application contains a package named main

The second line import "fmt" tells the GO compiler that this program uses the fmt package (functions or other elements). The fmt package implements formatted IO, (input/output) functions.

The third line, func main(), is the function where the program starts execution. The main function must be included in every executable program. Generally speaking, it is the first function to be executed after startup (if there is an int() function, this function will be executed first)

The fourth line, fmt.Printl() , outputs the string to the console and adds an automatic line break\n at the end.

Precautions:

{} cannot be placed on a separate line, it must be after the function, otherwise an error will be reported.

When identifiers (including constants, variables, types, function names, structure fields, etc.) start with an uppercase letter, such as Group1, then objects using this form of identifier can be used by external code (the client program needs Import this package first), which is called export (like public in object-oriented languages). If the identifier starts with a lowercase letter, it is not visible outside the package, but it is visible within the entire package.

Welcome everyone to follow my official account, learn knowledge about operation and maintenance, security, and development together, work hard together, and make progress together.

 

 

Guess you like

Origin blog.csdn.net/u011630259/article/details/132083768