在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 教程/ GO/ Go函數(shù)多個返回值實(shí)例
Go panic錯誤處理實(shí)例
Go命令行參數(shù)實(shí)例
Go可變參數(shù)的函數(shù)實(shí)例
Go通道同步實(shí)例
Go非阻塞通道操作實(shí)例
Go指針實(shí)例
Go數(shù)字解析實(shí)例
Go語言指針
Go超時(timeouts)實(shí)例
Go速率限制實(shí)例
Go信號實(shí)例
Go Base64編碼實(shí)例
Go計時器實(shí)例
Go命令行標(biāo)志實(shí)例
Go原子計數(shù)器實(shí)例
Go語言切片
Go隨機(jī)數(shù)實(shí)例
Go語言類型轉(zhuǎn)換
Go排序?qū)嵗?/span>
Go時間格式化/解析實(shí)例
Go URL解析實(shí)例
Go字符串函數(shù)實(shí)例
Go語言常量
Go for循環(huán)語句實(shí)例
Go函數(shù)多個返回值實(shí)例
Go切片實(shí)例
Go行過濾器實(shí)例
Go語言接口
Go語言數(shù)組
Go語言變量
Go字符串格式化實(shí)例
Go斷續(xù)器實(shí)例
Go if/else語句實(shí)例
Go通道緩沖實(shí)例
Go錯誤實(shí)例
Go語言映射
Go執(zhí)行過程實(shí)例
Go函數(shù)實(shí)例
Go有狀態(tài)的goroutines實(shí)例
Go按自定義函數(shù)排序?qū)嵗?/span>
Go語言作用域規(guī)則
Go時代(Epoch)實(shí)例
Go變量實(shí)例
Go互斥體實(shí)例
Go語言范圍(range)
Go程序?qū)嵗?/span>
Go語言入門
Go通道路線實(shí)例
Go閉包(匿名函數(shù))實(shí)例
Go Select實(shí)例
Go通道范圍實(shí)例
Go集合函數(shù)實(shí)例
Hello World程序?qū)嵗?/span>
Go環(huán)境變量實(shí)例
Go語言運(yùn)算符
Go讀取文件實(shí)例
Go延遲(defer)實(shí)例
Go SHA1哈希實(shí)例
Go語言條件和決策
Go語言錯誤處理
Go通道實(shí)例
Go指針實(shí)例
Go時間日期實(shí)例
Go語言字符串
Go語言循環(huán)
Go語言基礎(chǔ)語法
Go語言開發(fā)環(huán)境安裝配置
Go常量實(shí)例
Go語言結(jié)構(gòu)體
Go寫文件實(shí)例
Go正則表達(dá)式實(shí)例
Go JSON實(shí)例
Go語言教程
Go關(guān)閉通道實(shí)例
Go接口實(shí)例
Go語言遞歸
Go switch語句實(shí)例
Go函數(shù)遞歸實(shí)例
Go退出程序?qū)嵗?/span>
Go語言程序結(jié)構(gòu)
Go范圍實(shí)例
Go語言函數(shù)
Go工作池實(shí)例
Go語言數(shù)據(jù)類型

Go函數(shù)多個返回值實(shí)例

Go內(nèi)置支持多個返回值。此功能經(jīng)常用于通用的Go中,例如從函數(shù)返回結(jié)果和錯誤值。

所有的示例代碼,都放在 F:\worksp\golang 目錄下。安裝Go編程環(huán)境請參考:http://www.yiibai.com/go/go_environment.html

此函數(shù)簽名中的(int,int)表示函數(shù)返回2int類型值。
這里使用從多個賦值的調(diào)用返回2個不同的值。如果只想要返回值的一個子集,請使用空白標(biāo)識符_。
接受可變數(shù)量的參數(shù)是Go函數(shù)的另一個不錯的功能; 在接下來實(shí)例中可以來了解和學(xué)習(xí)。

multiple-return-values.go的完整代碼如下所示 -

package main

import "fmt"

// The `(int, int)` in this function signature shows that
// the function returns 2 `int`s.
func vals() (int, int) {
    return 3, 7
}

func main() {

    // Here we use the 2 different return values from the
    // call with _multiple assignment_.
    a, b := vals()
    fmt.Println(a)
    fmt.Println(b)

    // If you only want a subset of the returned values,
    // use the blank identifier `_`.
    _, c := vals()
    fmt.Println(c)
}

執(zhí)行上面代碼,將得到以下輸出結(jié)果 -

F:\worksp\golang>go run multiple-return-values.go
3
7
7