package main
import (
"fmt"
"math"
)
//常量的数值可以作为各种类型使用
func consts(){
const filename = "abc.txt"
//const a,b int= 3,4 常量可规定类型也可不规定
const a,b = 3,4
var c int
c = int(math.Sqrt(float64(a * a + b * b)))
fmt.Println(filename,c)
}
//枚举类型
func enums(){
const (
cpp = iota //const修饰的变量必须赋初值,iota表示自增
_
pyhon
golang
javascrtpt
)
const (
b = 1<<(10*iota)
kb
mb
gb
tb
)
fmt.Println(cpp,javascrtpt,pyhon,golang,)
fmt.Println(b,kb,mb,gb,tb)
}
func main() {
consts()
enums()
}
常量的数值可以作为各种类型使用
const修饰的变量必须赋初值,iota表示自增