美文网首页
Go_010_变量命名规则

Go_010_变量命名规则

作者: 为宇绸缪 | 来源:发表于2023-05-02 17:30 被阅读0次

变量命名规则
1、变量名称必须由数字、字母、下划线组成。
2、标识符开头不能是数字。
3、标识符不能是保留字和关键字
4、建议使用驼峰式命名,当名字有几个单词组成的时优先使用大小写分隔
5、变量名尽量做到见名知意。
6、变量命名区分大小写

关键字
go语言中有25个关键字,不能用于自定义变量名

break        default          func           interface         select
case         defer            go             map               struct
chan         else             goto           package           switch
const        fallthrough      if             range             type
continue     for              import         return            var

预定义名字
还有30多个预定义的名字,用于内建的常量、类型和函数

// 内建常量:
    true false iota nil
// 内建类型:
    int int8 int16 int32 int64
    uint uint8 uint16 uint32 uint64 uintptr
    float32 float64 complex128 complex64
    bool byte rune string error
// 内建函数:
    make len cap new append copy close delete
    complex real imag
    panic recover

相关文章

网友评论

      本文标题:Go_010_变量命名规则

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