go语言基础之常量

1、常量

示例:

package main //必须有一个main包

import "fmt"

func main() {
	//变量:程序运行期间,可以改变的量, 变量声明需要var
	//常量:程序运行期间,不可以改变的量,常量声明需要const

	const a int = 10
	//a = 20 //err, 常量不允许修改
	fmt.Println("a = ", a)

	const b = 11.2 //没有使用:=
	fmt.Printf("b type is %T
", b)
	fmt.Println("b = ", b)
} 

#执行结果:

a =  10
b type is float64
b =  11.2

  

原文地址:https://www.cnblogs.com/nulige/p/10199535.html