From 3f15fdd59fca51ce4f9bd8b0bb5e3c43df1b40b9 Mon Sep 17 00:00:00 2001 From: _Fighter Date: Fri, 3 Dec 2021 01:14:43 +0800 Subject: [PATCH] add --- basic.go | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++ helloworld.go | 12 ++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 basic.go create mode 100644 helloworld.go diff --git a/basic.go b/basic.go new file mode 100644 index 0000000..41ac020 --- /dev/null +++ b/basic.go @@ -0,0 +1,54 @@ +package main + +import "fmt" + +/*此处不能使用 := 来定义变量 + go 语言都中包内变量,go 没有全局变量 + 函数包变量可以不使用, +*/ +var xx =3 +var ss =100 +/*统一定义变量*/ +var( + x1=23 + x2=true + x3=323.23 +) + +func variableZeroValue() { + /*函数内部变量必须被使用*/ + var a int + var s string + fmt.Printf("%d %q\n", a, s) +} + +func variableInitialValue() { + var a ,b int = 3,4 + var s string = "abc" + fmt.Println(a,b, s) +} + + +func variableTypeDeduction() { + var x ,b ,c,e,f = 3.23,4,"abdad",true, 4.54 + fmt.Println(x,b,f+1, c,e) +} + +func variableShorter() { + /* + 不使用 var + 第一次定义变量可以使用:=,但是只能在函数内部使用,外部不能使用 + */ + x ,b ,c,e,f := 3.23,4,"abdad",true, 4.54 + fmt.Println(x,b,f+1, c,e) +} + + +func main() { + variableZeroValue() + variableInitialValue() + variableTypeDeduction() + variableShorter() + fmt.Println(x1,x2,x3) + +} diff --git a/helloworld.go b/helloworld.go new file mode 100644 index 0000000..623fe0f --- /dev/null +++ b/helloworld.go @@ -0,0 +1,12 @@ +package main + +import ( + "fmt" + "runtime" +) + +func main() { + + fmt.Println("hello world!") + fmt.Println(runtime.GOARCH) +} -- GitLab