3. Go语言—函数和常量

Posted hq82

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了3. Go语言—函数和常量相关的知识,希望对你有一定的参考价值。

一、函数声明和注释

1. 声明

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

func add
    pass


func add(a int, b int)
    


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

2. 注释

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

二、常量

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
)

以上是关于3. Go语言—函数和常量的主要内容,如果未能解决你的问题,请参考以下文章

Go语言-变量和常量

Go语言-变量和常量

go语言的主要特征

go语言的主要特征

1.go语言之常量和变量

Go语言基础变量和常量