package main import "fmt" /*const ( USA = 0 China = 1 Russia = 2 Britain = 3 France = 4 )*/ /*使用iota定义一组常量 后面的常量会自动沿用第一个的表达式(但iota的值会逐个递增)*/ const ( USA = iota + 1 China Russia Britain France ) const ( Spring = (iota+1)*2 Summer Autumn winter ) func main() { fmt.Println(USA, China, Russia, Britain, France) fmt.Println(Spring, Summer, Autumn, winter) }
输出结果:
1 2 3 4 5
2 4 6 8