[关闭]
@adamhand 2019-01-30T12:02:04.000000Z 字数 218 阅读 600

golang--常量


定义

常量使用const关键字修饰,初始化之后不能再重新赋值为其他的值。常量的值会在编译的时候确定。因为函数调用发生在运行时,所以不能将函数的返回值赋值给常量。

  1. package main
  2. import (
  3. "fmt"
  4. "math"
  5. )
  6. func main() {
  7. fmt.Println("Hello, playground")
  8. var a = math.Sqrt(4) // 允许
  9. const b = math.Sqrt(4) // 不允许
  10. }

常用常量

字符串常量

参考

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注