【Go】const

Constants can be understood as immutable numbers

Constants in go, that is, constant

Created at compile time, can only be numeric, string, boolean, and cannot be modified anymore

Constants can be defined explicitly or implicitly

1
2
3
4
5
// Explicit definition
const name string = "Bill Gates"

// implicitly defined, the go compiler will automatically infer the type of the constant based on the type of the value
const name = "Bill Gates

Constants can use iota to generate enum values

1
2
3
4
const (
    a = iota
    b = iota
)

The first iota is 0, so a is 0
When iota is used again, its value becomes 1, so b is 1

Constants cannot be declared using short variable syntax: =

Persist in original technology sharing, your support will encourage me to continue to create!