This is a creation in Article, where the information may have evolved or changed.
2. Toad Notes Go language--bag
Each Go program is made up of packages.
The entry that runs the program is the package main.
This program uses and imports the package "FMT" and "Math/rand".
By convention, the package name is consistent with the last directory of the import path. For example, the "Math/rand" package is started by the Packages Rand statement
Code
Package Main
Import (
"FMT"
"Math/rand"
)
Func Main () {
Fmt. Println ("Myfavorite number is", Rand. INTN (10))
}
EXECUTE as follows:
Myfavorite number is 1
Import
The code uses parentheses to combine the imports, which is the "package" import statement.
You can also write multiple import statements, such as:
Import "FMT"
Import "Math"
However, using packaged import statements is a better form.
Guide Famous
After you have imported a package, you can call it with its exported name.
In Go, the name of the initial capital letter is exported.
Both Foo and Foo are the exported names. The name Foo is not exported.
Executes the code. Then add Math. Pi renamed to Math.PI and try to execute again, will error.
Package Main
Import (
"FMT"
"Math"
)
Func Main () {
Fmt. Println (Math. Pi)
}