Skip to content

变量与常量 ​

自动推断类型 ​

go
    var a = "initial"
    fmt.Println(a)

主动设置类型 ​

go
    var b, c int = 1, 2
    fmt.Println(b, c)

简写 ​

go
    // var f string = "short" 的简写
    f := "short"

常量 ​

go
const s string = "constant"