This is a creation in Article, where the information may have evolved or changed.
The previous topic shows that the development environment of the go language under Ubuntu has been set up and we are going to conquer go, and to first understand the features of the go language, let's start with the simplest test "Hello world!" Test the code.
The implementation code in the Go language is very concise. The most test code is written below.
PackageMainImport "FMT"//import package, including print functionfuncMain () {FMT. Print ("Hello world!")///End Here can also be added '; '}tsong@tsong:~/exc$GoBuild Gotest.Go#编译 tsong@tsong:~/exc$./gotest #运行hello world!GoThe data type and use of the language inGoThere are many types of data built into the language that can be easily used by us, butGoThe definition and initialization of data types in, and C language is a bit different. Use keywords for life variablesvarFor example:varScorefloat64;varAgeint=Ten;//Declaration and initializationvarNamestring="Lizi"Price: =20.9;//System Automatic identification data typevarNumberint; number = -;var(Aint= -; Bint=Ten; ) inGoYou can also give names to literal constants in languages such as:ConstNamestring="China";//literal constant takes the name of the const keyword