Constants
Constants in Go are just that — constant. They are created at compile time,and can only be numbers, strings, or booleans; const x = 42
makes x
a constant. You can useiota5 to enumerate values.
const (
a = iota
b
)
The first use of iota
will yield 0, so a
is equal to 0. Whenever iota
isused again on a new line its value is incremented with 1, so b
has a value of 1.Or, as shown here, you can even let Go repeat the use of iota
. You may alsoexplicitly type a constant: const b string = "0"
. Now b
is a string
typeconstant.
当前内容版权归 Miek Gieben 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 Miek Gieben .