This is an explanation of the video content.
 用技术延续对ACG的热爱
88

 |   | 

Go_04 函数和常量

Go函数和常量

函数声明和注释

1.函数声明

//格式
func	函数名字(参数列表)(返回值列表){}

//例子
func add(){}

func add(a int,b int){}


func add(a int, b int)(int , int){}

2.注释,两种注释,单行注释:// 多行注释: /* */

//计算两个整数和,并返回结果
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)
}

1578769492567


常量优雅的写法

Var(
    a int
    b string
    c bool
    d = 8
    e = "hello world"
)

1578770099235

88 服务端 ↦ Go从0到1手把手教程 __ 124 字
 Go从0到1手把手教程 #5