码迷,mamicode.com
首页 > 编程语言 > 详细

3. Go语言—函数和常量

时间:2019-06-22 20:06:00      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:ons   列表   返回值   自增   使用   多行注释   number   不能   函数   

一、函数声明和注释

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语言—函数和常量

标签:ons   列表   返回值   自增   使用   多行注释   number   不能   函数   

原文地址:https://www.cnblogs.com/hq82/p/11069939.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!