| |
//格式
func 函数名字(参数列表)(返回值列表){}
//例子
func add(){}
func add(a int,b int){}
func add(a int, b int)(int , int){}
//计算两个整数和,并返回结果
func add(a int,b int) int{}
1.常量使用const修饰,代表永远只读,不能修改
2.const只能修饰boolean,number(int 相关类型,浮点类型,complex)和string
3.语法:const identifier[type] = value,其中type可以省略
const b string = "hello world"
const b = "hello world"
const Pi = 3.1415926
const a = 4/5
4.比较优雅的写法
const(
a = 0
b = 1
c = 2
)
5.更加专业的写法
const(
a = iota
b //1
c //2
)
打印当前时间:
func init(){
Second:=time.Now().Unix()
fmt.Println(Second)
}
常量优雅的写法
Var(
a int
b string
c bool
d = 8
e = "hello world"
)