iota定义常量
iota 1 //iota作用会自动递增,引用自己定义的表达式。 2 3 4 //定义所有星期,从0到6 5 package main 6 7 import "fmt" 8 9 const ( 10 Sunday = iota //重点 11 Monday 12 Tuesday 13 Wednesday 14 Thursday 15 Friday 16 Saturday 17 ) 18 19 func main() { 20 21 //从第二个开始,自动引用排头兵的表达式,但iota逐一递增. 22 fmt.Println(Sunday, Monday, Tuesday) //0 1 2 23 24 } 1 ////定义所有星期,从1到7 2 package main 3 4 import "fmt" 5 6 const ( 7 Monday = iota +1 //0 +1 = 1 //重点 8 Tuesday 9 Wednesday 10 Thursday 11 Friday 12 Saturday 13 Sunday 14 ) 15 16 func main() { 17 18 //从第二个开始,自动引用排头兵的表达式,但iota逐一递增. 19 fmt.Println(Monday, Tuesday) //1 2 20 21 } 1 //定义5大常任理事国编号100-500