This is a creation in Article, where the information may have evolved or changed.
I've always wondered why learning every language, starting with the first program is always Hello world, don't I write anything else, this language is not good to learn?
O (∩_∩) o haha ~, we do not delve into the here, or inherit the glorious tradition! The following is a completed Hello World program:
The package main ... ... ... ..... ... .... ... .... ... .... ..... .... ..... ..... ..... ..... ..... ..... .......-....... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ....... 1
Import(... ...) ... ... .... ... .... ... .... ... .... ... .... ..... ..... ..... ..... .... ..... ..... .....-.....-........ ... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ... 2
"FMT" ... ... ... ... ... ... ... ... ... ... .... ... .... ..... .... ..... ....., ..., ... and .... ..... ....? ....., ... and .... ....... ... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ... .. ..... ..... 3
)........................................................................................................................................................................ 4
FuncMain (){... ..... ... .... ... ..... ..... ..... ..... ..... ..... ....... .................. ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ....... 5
FMT. Println ("Helloworld!") .............................................................................. 6
}........................................................................................................................................................................ 7
Compile, the output after running is:
Hello world!
Let's analyze one of these codes (the numbers below represent the line numbers of the code):
1 should be like Java, put this file into a package, the registration is called Main
2 is the library file that imports the system
3 Use the Func key to define the function, and the Go Language program entry is the main function
4 calling the library function output string Hello World, note here: The go language rules, all exported functions or variables, the first letter must be capitalized.
It is also important to note that the Go Language program statement does not require a semicolon as a terminator.
Let's change this function:
The output of the program is:
Here are a few points of knowledge:
1. When there are multiple libraries that need to be imported, you can either have one () or import them separately:
2. The parameters of the function and the type of the return value are all back-mounted