3. Go language - functions and constants

First, the function declarations and comments

1. Declare

func 函数名 (参数列表)(返回值列表){}

func add{
    pass
}

func add(a int, b int){
    
}

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

2. Comment

1. // 单行注释
2. /* */ 多行注释

Second, the constant

1. 常量使用const修饰,代表永远是只读的,不能修改的
2. const 只能修饰boolean、number(int/float/complex)、string
3. 语法:const identifer[type] = value ,其中type可省略

const(
    a = 0
    b = 1
    c = 2
)
或
const(
    // a默认赋值0,后面自增1
    a = iota
    b
    c
)

Guess you like

Origin www.cnblogs.com/hq82/p/11069939.html
Recommended