This is a creation in Article, where the information may have evolved or changed.
Source code example (Bo Master is Liteide,gopath is directly in the IDE, view-and management Gopath added)
Package Mainimport "FMT" Func Main () {FMT. Printf ("Hello World")} Compiled output: Hello World success: Process exit code 0.
2. Code explanation
In the first row
Package main//This line is required, so the go file is in the packages <something> start,//to declare which packet this file belongs to. For standalone files, the package main must start with the same
In the second row
Import "FMT"//Represents the imported package, where the print function in the FMT package is used, so the package must be imported. This is the same as importing packages in Java//If you need to use more than one package: import ("FMT" "bytes" "io") can also: import "fmt", "bytes", "IO"
In the third row
The func//keyword is used to define a function, such as if you want to write a demo function yourself, it should be defined as: Func demo () {//other code}//the third row of main () is roughly the same as in other languages
In line four
Fmt. printf ()//Use the printf function in the FMT package, which is a print function. In a custom package, generally speaking, the package name should be lowercase, the function capital begins with the object-oriented public function, the function starts with lowercase, the equivalent of the private function