1. package main
    2. import "fmt"
    3. //const 来定义枚举类型
    4. const(
    5. BEIJING = 0
    6. SHANGHAI = 1
    7. SHANDONG = 2
    8. )
    9. const(
    10. //可以在 const() 添加一个关键字 iota,每行iota都会累加1,第一行的iota的默认值是0
    11. //iota只能在const一起使用
    12. JINAN = iota //iota = 0
    13. QINGDAO //iota = 1
    14. TAIAN //iota = 2
    15. )
    16. const(
    17. AA = 10*iota //iota = 0
    18. BB //iota = 1
    19. CC //iota = 2
    20. )
    21. const(
    22. a,b = iota+1,iota+2 // iota = 0 ,a = 1,b = 2
    23. c,d //iota = 1,c = 2, d = 3
    24. e,f //iota = 2,e = 3, f = 4
    25. g,h = iota*2,iota*3 //iota = 3,g = 6,h = 9
    26. i,k //iota = 4,i = 8,k = 12
    27. )
    28. func main() {
    29. //常量(只读属性,不允许修改)
    30. const length int = 10
    31. fmt.Println(length)
    32. fmt.Println("JINAN = ",JINAN) //JINAN = 0
    33. fmt.Println("QINGDAO = ",QINGDAO) //QINGDAO = 1
    34. fmt.Println("TAIAN = ",TAIAN) //TAIAN = 2
    35. fmt.Println("AA = ",AA) //AA = 0
    36. fmt.Println("BB = ",BB) //BB = 10
    37. fmt.Println("CC = ",CC) //CC = 20
    38. }