package main
import "fmt"
func main() {
/*
常量: 1.概念:同变量类似,程序执行过程中数值不能改变 2.语法:
显式类定义
隐式类定义 3.常数
固定的数值:100,”abc“
*/
fmt.Println(100)
fmt.Println("hello")
//1.定义常量
const path string ="www.baidu.com"
const pi =3.14
fmt.Println(path)
fmt.Println(pi)
//2.尝试修改常量的数值
//path = "www.sougou.com"//cannot assign to path
//3.定义一组常量
const C1,C2,C3 =100,3.14,"HAHA"
const (
MALE =0
FEMALE =1
UNKNOW =3
)
//4.一组常量中,如果某个常量没有初始值,默认和上一行一致
const (
a int =100
b
c string ="ruby"
d
e
)
fmt.Printf("%T,%d\n",a,a)
fmt.Printf("%T,%d\n",b,b)
fmt.Printf("%T,%s\n",c,c)
fmt.Printf("%T,%s\n",d,d)
fmt.Printf("%T,%s\n",e,e)
//5.枚举类型,使用常量组作为枚举类型,一组相关数值的数据
const (
SPRING =0
SUMMER =1
AUTUMN =2
WINTER =3
)
}
运行结果:
GOROOT=D:\Go #gosetup
GOPATH=D:\gopath #gosetup
D:\Go\bin\go.exe build -o C:\Users\Administrator\AppData\Local\Temp\___go_build_Demo_Jc_con.exe Demo/Jc_con #gosetup
C:\Users\Administrator\AppData\Local\Temp\___go_build_Demo_Jc_con.exe #gosetup
100
hello
www.baidu.com
3.14
int,100
int,100
string,ruby
string,ruby
string,ruby
Process finished with exit code 0
读完点个赞,给我的坚持更新注入新的活力。
2022.04.10日更51/365 天
公众号:3天时间
网友评论