funcmain(){const PI =3.1415
fmt.Println(PI)// iota 自增常量const(
a =iota
b, c, d =iota,iota,iota
e =iota)
fmt.Println(a)
fmt.Println(b)
fmt.Println(c)
fmt.Println(d)
fmt.Println(e)}
func
funcfoo(args ...int){for_, value :=range(args){
fmt.Println(value)}}funcfooo(args ...int){//foo(args...)foo(args[0:]...)}funcretfunc1()int{return666}funcretfunc2()(result int){return666}funcretfunc3()(result int){
result=666return}funcmultiretfunc1()(int,int,int){return1,2,3}funcmultiretfunc2()(a int, b int, c int){return1,2,3}funcmultiretfunc3()(a int, b int, c int){
a, b, c =1,2,3return}funcAdd(a, b int)int{return a + b
}funcmain(){foo(multiretfunc3())}
funcmain(){
slice :=[]int{1,2,3,4,5}
s2 := slice[1:4]
s2[0]=6
fmt.Println(slice)
s :=[]int{}
fmt.Printf("%p", s)
s =append(s,1)
fmt.Println()
fmt.Printf("%p", s)}
struct
type user struct{
name string
age int}func(u user)changeage(newage int){
u.age = newage
}func(u user)print(){
fmt.Println("name ", u.name)
fmt.Println("age ", u.age)}funcmain(){
u :=&user {"haha",10}(*u).changeage(20)(*u).print()var time time2.Time = time2.Now()
fmt.Println(time)}
var
funcmain(){// var 声明var value1 int=123// 或者var value2 int
value2 =123// 不指定自动推导类型var value3 =123// 集中声明var(
ivalue int
fvalue float64
svalue string)
ivalue, fvalue, svalue =234,3.1415,"abc"// 不使用var,使用:= ,会自动推导类型
value4 :=123// 同时声明多个变量
a, b, c :=1,2,3
fmt.Println(value1)
fmt.Println(value2)
fmt.Println(value3)
fmt.Println(value4)
fmt.Println(ivalue)
fmt.Println(fvalue)
fmt.Println(svalue)
fmt.Println(a)
fmt.Println(b)
fmt.Println(c)var aaa int=123
fmt.Printf("%T", aaa)}