package main import "fmt" //全局变量,赋值 var( PI float32 = 3.1415 Count int = 56 ) //全局变量,无值 var( x string y string ) func main() { var i1 = true var i2 bool = true var i3 bool //默认false i4 := true var i5,i6 = 1,2 //类型相同多个变量, 非全局变量 var i7,i8 int i7,i8 = 1,2 i9,i10 := 1,2 var i11,i12 = true, "123" //不同类型相同多个变量, 非全局变量 fmt.Println(PI) fmt.Println(Count) x = "xxxxx" y = "yyyyy" fmt.Println(x) fmt.Println(y) fmt.Println(i1) fmt.Println(i2) fmt.Println(i3) fmt.Println(i4) fmt.Println(i5) fmt.Println(i6) fmt.Println(i7) fmt.Println(i8) fmt.Println(i9) fmt.Println(i10) fmt.Println(i11) fmt.Println(i12) fmt.Println("Hello, World2!") }
package main const PI = 3.1415 const Earth = 6371 const ( X = 3.14 Y = 6371 ) func main() { println(PI) println(Earth) println(X) println(Y) }