兰 亭 墨 苑
期货 · 量化 · AI · 终身学习
首页
归档
编辑文章
标题 *
URL 别名 *
内容 *
(支持 Markdown 格式)
# Go Learning Path - Module 1: Hello World & Basic Concepts ### go教程目录 [Module 1: Hello World & Basic Concepts ](https://blog.want.biz/post/1765795129286 ) [Module 2: Variables, Data Types, and Constants](https://blog.want.biz/post/1765795175801) [Module 3: Functions, Methods, and Packages](https://blog.want.biz/post/1765795198806) [Module 4: Control Structures (if/else, loops)](https://blog.want.biz/post/1765795229969) [Module 5: Arrays, Slices, and Maps Arrays](https://blog.want.biz/post/1765795259076) [Module 6: Structs and Interfaces](https://blog.want.biz/post/1765795286345) [Module 7: Pointers and Memory Management](https://blog.want.biz/post/1765795309147) [Module 8: Concurrency with Goroutines and Channels](https://blog.want.biz/post/1765795409315) [Module 9: Error Handling and Defer/Panic/Recover](https://blog.want.biz/post/1765795435815) [Module 10: Advanced Topics - Testing and Standard Library](https://blog.want.biz/post/1765795463803) Welcome to Go programming! Go (also known as Golang) is a statically typed, compiled programming language designed at Google. This module introduces you to the basics of Go. ## Hello World Program Let's start with the classic "Hello, World!" program: ```go package main import "fmt" func main() { fmt.Println("Hello, World!") } ``` ### Explanation: - `package main` - Every Go program starts with a package declaration. The `main` package is special - it defines a standalone executable program. - `import "fmt"` - Imports the `fmt` package which provides formatted I/O functions. - `func main()` - The entry point function that gets executed when the program runs. - `fmt.Println()` - Prints the string followed by a newline. ## How to Run Go Programs Save your code in a file ending with `.go` extension (e.g., `hello.go`) and run: ```bash go run hello.go ``` To compile and generate an executable: ```bash go build hello.go ./hello # On Unix/Linux/Mac hello.exe # On Windows ``` ## Package Declaration Every Go program belongs to a package. Packages help organize and reuse code: ```go package main // For executable programs // Or for libraries package utils // A reusable package named 'utils' ``` ## Import Statements You can import multiple packages: ```go package main import ( "fmt" "math" ) func main() { fmt.Println("Square root of 16 is:", math.Sqrt(16)) } ``` ## Comments Go supports single-line and multi-line comments: ```go // This is a single-line comment /* This is a multi-line comment */ ``` ## Exercises 1. Modify the hello world program to print your name. 2. Create a program that prints multiple lines using multiple `Println` statements. 3. Experiment with the `fmt.Print()` function to see how it differs from `fmt.Println()`. --- Next: [Module 2: Variables, Data Types, and Constants](02-variables-data-types-constants.md)
配图 (可多选)
选择新图片文件或拖拽到此处
标签
更新文章
删除文章