多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
## 常量的类型 ~~~go const CONST [type] = value # 显示 const CONST = value # 隐式 ~~~ > 定义 > 常量在编译时就已经确定 > 常量可由内置表达式计算,表达式中的函数必须是内置函数 > 只支持布尔型,数字型,字符串型 ## 特殊常量iota > iota在const关键字出现时,将会被重置为0 > const中每新增一行常量声明iota计数一次(分组声明中) ~~~go const ( a = iota b c ) fmt.Printf("a=%d b=%d c=%d", a, b, c) ~~~ ### example ```go package constant_test import "testing" const ( Readable = 1 << iota Writable Executable ) func TestConstantTry1(t *testing.T) { a := 1 //0001 t.Log(a&Readable == Readable, a&Writable == Writable, a&Executable == Executable) } ```