美文网首页go
Go入门7:常量 const

Go入门7:常量 const

作者: 副班长国伟 | 来源:发表于2018-06-14 15:44 被阅读0次

    const关键字

    const variable type = value;

    简单定义:

    const LENGTH int = 10

    const WIDTH int = 5

    块形式定义:

    const (
        LENGTH int = 10
        WIDTH int = 8
    )

    或者:

    const (
        Cat = 10
        Dog = 20
        Bird = 30
    )

    fmt.Println(LENGTH)    // 10

    未使用的常量不会引发编译器错误!!!

    不能给常量进行重新赋值!

    可以一行声明多个常量:

    const name, size = "carrot", 100


    相关文章

      网友评论

        本文标题:Go入门7:常量 const

        本文链接:https://www.haomeiwen.com/subject/pexgkftx.html