# 03-型別

## Types

我們在上一章用字串資料型別儲存 `Hello World`，資料型別將相關值的集合分類為一組，說明可進行的資料型別操作，以及定義儲存資料的方式。因為型別的概念不好掌握，所以在我們開始研究如何用 Go 實做以前，要先從幾個不同的觀點來看。

哲學家有時會對型別與 token 進行區分，比如假設你有一條叫做 Max 的狗，Max 就是 token（一個特殊的實體「instance」或成員），而 dog 就是型別（通用概念）。"Dog" 或 "dogness" 表示每條狗都有的一組屬性（property）。雖然過於簡化，不過我們可以這樣解釋：因為全部的狗都有 4 條腿，而 Max 是條狗，所以 Max 有 4 條腿。在程式語言中的型別以簡單的方式運作：全部的字串都有長度，而 x 是個字串，因此 x 有長度。

我們在數學經常談論集合，比如：ℝ（全部實數的集合）或 ℕ（全部自然數的集合）。這些集合的每個數與集合裡的其它成員共享屬性。比如全部的自然數都相關的：＂對於全部的自然數 a、b 及 c，a + (b + c) = (a + b) + c，而 a × ( b × c ) = (a × b) × c＂。在這個方式，集合就類似是程式語言的型別，因為一個屬性型別的每個值都彼此共用某些屬性。

Go 是個靜態型別的（statically typed）程式語言，這表示變數永遠有特定的型別，而且該型別無法改變。靜態型別或許一開始看起來很討人厭，你在最後編譯程式時會耗費大量的時間在修正程式，可是型別讓我們可以合理的解釋程式在做什麼，並找出各種常見的錯誤。

我們將詳細的探討幾個 Go 內建的資料型別。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://go.netdpi.net/type.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
