From a615561fb8ea83673632c8286a57ab52dc16eb14 Mon Sep 17 00:00:00 2001 From: Wonder Date: Fri, 13 Mar 2026 23:58:18 +0800 Subject: [PATCH] =?UTF-8?q?Finish:=2001-variables=20-=20=E5=8F=98=E9=87=8F?= =?UTF-8?q?=E5=A3=B0=E6=98=8E=E4=B8=8E=E4=BD=9C=E7=94=A8=E5=9F=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- stage01-basics/01-variables/main.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/stage01-basics/01-variables/main.go b/stage01-basics/01-variables/main.go index 7aa052c..04b8c29 100644 --- a/stage01-basics/01-variables/main.go +++ b/stage01-basics/01-variables/main.go @@ -41,7 +41,7 @@ func exercise2() { price := 99.5 // 使用:=声明多个变量,x=10, y=20, z=30 - x, y, z := ____ + x, y, z := 10, 20, 30 fmt.Printf("城市: %s, 价格: %.2f, 坐标: (%d, %d, %d)\n", city, price, x, y, z) } @@ -57,10 +57,10 @@ func exercise3() { // level: int = 1 // experience: float64 = 0.0 var ( - username ____ - email ____ - level ____ - experience ____ + username string = "go_learner" + email string = "learner@example.com" + level int = 1 + experience float64 = 0.0 ) fmt.Printf("用户: %s\n邮箱: %s\n等级: %d\n经验值: %.1f\n", @@ -73,10 +73,10 @@ func exercise4() { fmt.Println("\n=== 练习4:变量作用域 ===") // 直接打印全局变量globalVar的值 - fmt.Printf("全局变量 globalVar 的值: %d\n", ____) + fmt.Printf("全局变量 globalVar 的值: %d\n", globalVar) // 声明一个局部变量,命名为localVar,值为50 - localVar := ____ + localVar := 50 fmt.Printf("局部变量 localVar 的值: %d\n", localVar) } @@ -92,7 +92,7 @@ func exercise5() { if true { // 在if代码块内声明一个同名的变量,值为"我是内层变量" // 这会遮蔽外层的outer变量 - outer := ____ + outer := "我是内层变量" fmt.Printf("代码块内: %s\n", outer) }