> For the complete documentation index, see [llms.txt](https://denglj.gitbook.io/essential-go/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://denglj.gitbook.io/essential-go/02-basic-types/lei-xing-zhuan-huan.md).

# 类型转换

跟C不同，Go并不会进行隐式类型转换。

您必须显式地，在可兼容的类型之间进行转换。

```go
package main

import "fmt"

func main() {
	// 您可以在数值之间转换，例如各种int和float类型
	var i1 int32 = 3
	var i2 int = int(i1) // 要把int32转为int必须显式地进行
	var f float64 = float64(i1)
	fmt.Println(i1, i2, f)

	s := "string"
	// 我们也可以在 string 和 []byte 之间互转
	// 注意，除非编译器优化，否则这涉及内存分配
	var d []byte = []byte(s)
	fmt.Println(s, d)
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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://denglj.gitbook.io/essential-go/02-basic-types/lei-xing-zhuan-huan.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.
