package main import "fmt" var luckyNum = 6 var luckyStr = "love" //myNum := 6 //在函数外部不可以用 := //合并定义 var ( age = 18 name = "jukai" ) //变量初值 func variableZeroValue() { var a int var s string var isOK bool fmt.Print(a, s, isOK) } //变量赋值 func variableInitValue() { var a, b int = 3, 4 var s string = "abc" fmt.Println(a, b, s) } //变量类型推断 func variableTypeDeduction() { var a, b, c, s = 3, 4, true, "def" fmt.Println(a, b, c, s) } //变量简短定义 := func variableShorter() { // := 定义并赋值 a, b, c, s := 3, 4, true, "def" num := 100 fmt.Println(a, b, c, s, num) } func main() { //变量初值 variableZeroValue() //变量赋值 variableInitValue() //变量类型推断 variableTypeDeduction() //变量简短定义 := variableShorter() //函数外部定义 print(age, name) }