This is a creation in Article, where the information may have evolved or changed.
1. Import the package, a main function has only one main function, contains a main package, the main function we want to declare the main package!
[Php]package Main
Func Main () {
}
[/php]
2. Introduce package files, for example, we use the FMT package, print Helloword, Golang has a package visibility definition, such as private in other languages, protected these declarations. When the handwritten letter is lowercase is available in the package, outside the package can not be used, handwritten letters uppercase, reference package can be used! As an example: FMT. Println (); we'll find that the functions we use and reference are capitalized! The lowercase will call the wrong!
[Php]package Main
Import "FMT"
Func Main () {
Fmt. Println ("Hello, Micro Network");
}[/php]
3. Package obfuscation mechanism, we can package the alias, for example, we feel that the package cannot remember or say the name of the package is similar to the use of this alias mechanism!
[Php]package Main
Import str "FMT"
Package Main () {
Str. Println ("Hello, Micro Network");
}[/php]
4. Shorthand for multiple packages, constants, global variables, generic types, and more. When we have multiple constants, packages and so on how to declare it
[Php]import (const (VAR (
"FMT" PI = "3.1415926" name =1
"NET" NAME = "Widuu" Age =12
"IO" age = "a" Wo = "Me"
))) [/php]
Type of 5.Go
[Php]bool Boolean has true false without 0 and 1
int integer type based on platform custom if you're 32-bit, it's a 32-bit integer.
int8 8-bit integer in -128~256 This value range is actually 2 of the value of 8 square, signed is negative, uint8 is unsigned
Int16 16-bit integral type
Rune 32-bit signed integer
Int64 64-bit integral type
FLOAT32/64 bit
complex64/complex128 Negative Type
Other types
Array Slice string
Reference type
Slice Map Chan
Interface type interface
function Type func[/php]
5. Declaration of variables and value of assignment and declaration
We affirm that when there is no assignment, we will find such a
When declared int float output is 0 declaration bool output is false
The reference packet math outputs the maximum value and the minimum value, such as the value of the maximum Int16 range FMT. Println (Math. MaxInt16)
6. Type declaration We can customize the type declaration, such as the following
[Php]package Main
Import Std "FMT"
Type text string
Func Main () {
var a text
A = "Hello"
Std. Println (a)
}[/php]
7. Type Conversion
[Php]var a float32 = 100.01
B:=int (a)//output A is the value of 100.01 output B is 100
var c int = 65
D:=string (c)//output is a which is directly converted to text form a
B:=strconv. Itoa (c)//So the output is 65 direct text output [/php]
Do not reprint any article of this station without permission: Micro network emoji (Golang) language Learning (1)