You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
整理一些比較重要或 tricky 的 Go 語法或標準函式庫用法。
Tip: 到 Go Playground 寫點程式來測試和驗證自己的理解。
變數 宣告變數時,可使用關鍵字 var,並使用 = 運算子來賦值。
範例:
var x int var y int = 100 沒有設定初始值的變數,都會有一個預設值。對 int 型別而言,這個預設值是 0,故此範例的 x 初始值為 0。
另一種更簡潔的語法是用 := 運算子來一次完成兩件事:宣告變數且賦值,而且不用寫 var。此寫法稱為 short declaration syntax。
範例:
sum := 100 // sum 是一個整數。 str := "hello" // str 是一個字串。
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
docs/go/05-important-basics/
整理一些比較重要或 tricky 的 Go 語法或標準函式庫用法。
Tip: 到 Go Playground 寫點程式來測試和驗證自己的理解。
變數 宣告變數時,可使用關鍵字 var,並使用 = 運算子來賦值。
範例:
var x int var y int = 100 沒有設定初始值的變數,都會有一個預設值。對 int 型別而言,這個預設值是 0,故此範例的 x 初始值為 0。
另一種更簡潔的語法是用 := 運算子來一次完成兩件事:宣告變數且賦值,而且不用寫 var。此寫法稱為 short declaration syntax。
範例:
sum := 100 // sum 是一個整數。 str := "hello" // str 是一個字串。
https://huanlin.cc/docs/go/05-important-basics/
Beta Was this translation helpful? Give feedback.
All reactions