【go语言学习】常量 (快速设置连续值)
快速设置连续值 ,注意常量必须单独成行
//特殊
const (
Test1 = iota
Test2 = iota
Test3,Test4,Test5 = iota,iota,iota
Test6 = iota
)
//星期
const (
Monday = 1 + iota
Tuesday
Wednesday
Thursday
Friday
Saturday
Sunday
)
//按位操作
const (
Readable = 1 << iota
Writable
Executable
)
func main() {
fmt.Println(Monday, Tuesday,Wednesday)
a := 2
fmt.Println(Readable, Writable, Executable)
fmt.Println(a&Readable == Readable, a&Writable == Writable, a&Executable == Executable)
fmt.Printf("%d\n",Test1)
fmt.Printf("%d\n",Test2)
fmt.Printf("%d\n",Test3)
fmt.Printf("%d\n",Test4)
fmt.Printf("%d\n",Test5)
fmt.Printf("%d\n",Test6)
}
执行返回
go run test.go
1 2 3
1 2 4
false true false
0
1
2
2
2
3