1.3 KiB
1.3 KiB
2.8 總結
這一章我們主要介紹了Go語言的一些語法,透過語法我們可以發現Go是多麼的簡單,只有二十五個關鍵字。讓我們再來回顧一下這些關鍵字都是用來幹什麼的。
break default func interface select
case defer go map struct
chan else goto package switch
const fallthrough if range type
continue for import return var
- var和const參考2.2Go語言基礎裡面的變數和常量申明
- package和import已經有過短暫的接觸
- func 用於定義函式和方法
- return 用於從函式返回
- defer 用於類似解構函式
- go 用於併發
- select 用於選擇不同型別的通訊
- interface 用於定義介面,參考2.6小節
- struct 用於定義抽象資料型別,參考2.5小節
- break、case、continue、for、fallthrough、else、if、switch、goto、default這些參考2.3流程介紹裡面
- chan用於channel通訊
- type用於宣告自訂型別
- map用於宣告map型別資料
- range用於讀取slice、map、channel資料
上面這二十五個關鍵字記住了,那麼Go你也已經差不多學會了。