diff --git "a/translation/chinese/06-\345\217\230\351\207\217/01-\345\237\272\347\241\200\346\225\260\346\215\256\347\261\273\345\236\213/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/01-\345\237\272\347\241\200\346\225\260\346\215\256\347\261\273\345\236\213/main.go" new file mode 100644 index 000000000..f1743a0a1 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/01-\345\237\272\347\241\200\346\225\260\346\215\256\347\261\273\345\236\213/main.go" @@ -0,0 +1,38 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import "fmt" + +func main() { + // 整数型 + fmt.Println( + -200, -100, 0, 50, 100, 100, + ) + + // 浮点型 + fmt.Println( + -50.5, -20.5, -0., 1., 100.56, // ... + ) + + // 布尔值 + fmt.Println( + true, false, + ) + + // 字符串 - utf-8 + fmt.Println( + "", // 空字符串, 只打印一个空格 + "hi", + + // unicode + "nasılsın?", // 土耳其语的 "你好吗" + "hi there 星!", // "你好,star!" + ) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/01-\345\237\272\347\241\200\346\225\260\346\215\256\347\261\273\345\236\213/\347\273\203\344\271\240/01-print-the-literals/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/01-\345\237\272\347\241\200\346\225\260\346\215\256\347\261\273\345\236\213/\347\273\203\344\271\240/01-print-the-literals/main.go" new file mode 100644 index 000000000..d49ac649e --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/01-\345\237\272\347\241\200\346\225\260\346\215\256\347\261\273\345\236\213/\347\273\203\344\271\240/01-print-the-literals/main.go" @@ -0,0 +1,28 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +// --------------------------------------------------------- +// 练习: 打印字面量 +// +// 1. 打印一些整数型 +// +// 2. 打印一些浮点型 +// +// 3. 打印 true 和 false 的布尔值 +// +// 4. 用字符串打印你的名字 +// +// 5. 用字符串打印一句非英文的句子 +// +// --------------------------------------------------------- + +func main() { + // 使用 fmt.Println() +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/01-\345\237\272\347\241\200\346\225\260\346\215\256\347\261\273\345\236\213/\347\273\203\344\271\240/01-print-the-literals/solution/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/01-\345\237\272\347\241\200\346\225\260\346\215\256\347\261\273\345\236\213/\347\273\203\344\271\240/01-print-the-literals/solution/main.go" new file mode 100644 index 000000000..b58abd27a --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/01-\345\237\272\347\241\200\346\225\260\346\215\256\347\261\273\345\236\213/\347\273\203\344\271\240/01-print-the-literals/solution/main.go" @@ -0,0 +1,19 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import "fmt" + +func main() { + fmt.Println(42, 8500, 344433, -2323) + fmt.Println(3.14, 6.28, -42.) + fmt.Println(true, false) + fmt.Println("Hi! I'm Inanc!") + fmt.Println("Merhaba, adım İnanç!") +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/01-\345\237\272\347\241\200\346\225\260\346\215\256\347\261\273\345\236\213/\347\273\203\344\271\240/02-print-hexes/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/01-\345\237\272\347\241\200\346\225\260\346\215\256\347\261\273\345\236\213/\347\273\203\344\271\240/02-print-hexes/main.go" new file mode 100644 index 000000000..41f97d963 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/01-\345\237\272\347\241\200\346\225\260\346\215\256\347\261\273\345\236\213/\347\273\203\344\271\240/02-print-hexes/main.go" @@ -0,0 +1,69 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import "fmt" + +// 这个练习是可选的 + +// --------------------------------------------------------- +// 练习: 打印十六进制 +// +// 1. 打印十六进制的 0 到 9 +// +// 2. 打印十六进制的 10 到 15 +// +// 3. 打印十六进制的 17 +// +// 4. 打印十六进制的 25 +// +// 5. P打印十六进制的 50 +// +// 6. 打印十六进制的 100 +// +// 期望输出 +// 0 1 2 3 4 5 6 7 8 9 +// 10 11 12 13 14 15 +// 17 +// 25 +// 50 +// 100 +// +// NOTE +// https://stackoverflow.com/questions/910309/how-to-turn-hexadecimal-into-decimal-using-brain +// +// https://simple.wikipedia.org/wiki/Hexadecimal_numeral_system +// +// --------------------------------------------------------- + +func main() { + // 例子 + + // 我要打印十六进制的 10 + fmt.Println(0xa) + + // 我要打印十六进制的 16 + // 0x10 + // ^^----- 1 * 0 = 0 + // | + // +------ 16 * 1 = 16 + // = 16 + fmt.Println(0x10) + + // 我要打印十六进制的 150 + // 0x96 + // ^^----- 1 * 6 = 6 + // | + // +------ 16 * 9 = 144 + // = 150 + fmt.Println(0x96) + + // 把上面的所有代码注释掉, 然后 + // 在下面写下你的代码 +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/01-\345\237\272\347\241\200\346\225\260\346\215\256\347\261\273\345\236\213/\347\273\203\344\271\240/02-print-hexes/solution/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/01-\345\237\272\347\241\200\346\225\260\346\215\256\347\261\273\345\236\213/\347\273\203\344\271\240/02-print-hexes/solution/main.go" new file mode 100644 index 000000000..a6c54a5ce --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/01-\345\237\272\347\241\200\346\225\260\346\215\256\347\261\273\345\236\213/\347\273\203\344\271\240/02-print-hexes/solution/main.go" @@ -0,0 +1,20 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import "fmt" + +func main() { + fmt.Println(0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9) + fmt.Println(0xa, 0xb, 0xc, 0xd, 0xe, 0xf) + fmt.Println(0x11) // 17 + fmt.Println(0x19) // 25 + fmt.Println(0x32) // 50 + fmt.Println(0x64) // 100 +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/01-\345\237\272\347\241\200\346\225\260\346\215\256\347\261\273\345\236\213/\347\273\203\344\271\240/README.md" "b/translation/chinese/06-\345\217\230\351\207\217/01-\345\237\272\347\241\200\346\225\260\346\215\256\347\261\273\345\236\213/\347\273\203\344\271\240/README.md" new file mode 100644 index 000000000..f66e605ea --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/01-\345\237\272\347\241\200\346\225\260\346\215\256\347\261\273\345\236\213/\347\273\203\344\271\240/README.md" @@ -0,0 +1,9 @@ +1. **[打印字面量](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/01-基础数据类型/练习/01-print-the-literals)** + + 使用字面量打印一些值 + +2. **[打印十六进制数](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/01-基础数据类型/练习/02-print-hexes)** (可选练习) + + 打印十六进制的数 + + diff --git "a/translation/chinese/06-\345\217\230\351\207\217/01-\345\237\272\347\241\200\346\225\260\346\215\256\347\261\273\345\236\213/\351\227\256\351\242\230/README.md" "b/translation/chinese/06-\345\217\230\351\207\217/01-\345\237\272\347\241\200\346\225\260\346\215\256\347\261\273\345\236\213/\351\227\256\351\242\230/README.md" new file mode 100644 index 000000000..7df63dad9 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/01-\345\237\272\347\241\200\346\225\260\346\215\256\347\261\273\345\236\213/\351\227\256\351\242\230/README.md" @@ -0,0 +1,38 @@ +## 下面哪个是整数型 (int)? + +* -42 *正确* + * 这是整数型 +* "Hello" + * 这是字符串 +* false + * 这是布尔值 +* 3.14 + * 这是浮点型 + +## 下面哪个是浮点型 (float)? + +* -42 +* "Hello" +* false +* 3.14 *正确* + +## 下面哪个是浮点型 (float)? + +* 6,28 +* ,28 +* .28 *正确* +* 628 + +## 下面哪个是字符串 (string)? + +* -42 +* "Hello" *正确* +* false +* 3.14 + +## 下面哪个是布尔值 (bool)? + +* -42 +* "Hello" +* false *正确* +* 3.14 \ No newline at end of file diff --git "a/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/01-\345\243\260\346\230\216\350\257\255\346\263\225/01-\350\257\255\346\263\225/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/01-\345\243\260\346\230\216\350\257\255\346\263\225/01-\350\257\255\346\263\225/main.go" new file mode 100644 index 000000000..62742eabc --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/01-\345\243\260\346\230\216\350\257\255\346\263\225/01-\350\257\255\346\263\225/main.go" @@ -0,0 +1,17 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import "fmt" + +func main() { + var speed int + + fmt.Println(speed) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/01-\345\243\260\346\230\216\350\257\255\346\263\225/02-\345\221\275\345\220\215\350\247\204\345\210\231/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/01-\345\243\260\346\230\216\350\257\255\346\263\225/02-\345\221\275\345\220\215\350\247\204\345\210\231/main.go" new file mode 100644 index 000000000..277c7c00d --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/01-\345\243\260\346\230\216\350\257\255\346\263\225/02-\345\221\275\345\220\215\350\247\204\345\210\231/main.go" @@ -0,0 +1,26 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +// 变量声明规则 + +func main() { + // 正确的声明 + var speed int + var SpeeD int + + // 下划线开头是允许但不推荐的 + var _speed int + + // Unicode 字母是允许的 + var 速度 int + + // 让编译器开心 + _, _, _, _ = speed, SpeeD, _speed, 速度 +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/01-\345\243\260\346\230\216\350\257\255\346\263\225/03-\345\243\260\346\230\216\351\241\272\345\272\217/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/01-\345\243\260\346\230\216\350\257\255\346\263\225/03-\345\243\260\346\230\216\351\241\272\345\272\217/main.go" new file mode 100644 index 000000000..20590ce29 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/01-\345\243\260\346\230\216\350\257\255\346\263\225/03-\345\243\260\346\230\216\351\241\272\345\272\217/main.go" @@ -0,0 +1,14 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +func main() { + // fmt.Println(speed) + // var speed int +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/02-\345\243\260\346\230\216\347\244\272\344\276\213/01-int/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/02-\345\243\260\346\230\216\347\244\272\344\276\213/01-int/main.go" new file mode 100644 index 000000000..2c84852b9 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/02-\345\243\260\346\230\216\347\244\272\344\276\213/01-int/main.go" @@ -0,0 +1,23 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import "fmt" + +func main() { + var nFiles int + var counter int + var nCPU int + + fmt.Println( + nFiles, + counter, + nCPU, + ) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/02-\345\243\260\346\230\216\347\244\272\344\276\213/02-float64/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/02-\345\243\260\346\230\216\347\244\272\344\276\213/02-float64/main.go" new file mode 100644 index 000000000..0a9383174 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/02-\345\243\260\346\230\216\347\244\272\344\276\213/02-float64/main.go" @@ -0,0 +1,23 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import "fmt" + +func main() { + var heat float64 + var ratio float64 + var degree float64 + + fmt.Println( + heat, + ratio, + degree, + ) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/02-\345\243\260\346\230\216\347\244\272\344\276\213/03-bool/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/02-\345\243\260\346\230\216\347\244\272\344\276\213/03-bool/main.go" new file mode 100644 index 000000000..2f0f6b0b3 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/02-\345\243\260\346\230\216\347\244\272\344\276\213/03-bool/main.go" @@ -0,0 +1,23 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import "fmt" + +func main() { + var off bool + var valid bool + var closed bool + + fmt.Println( + off, + valid, + closed, + ) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/02-\345\243\260\346\230\216\347\244\272\344\276\213/04-string/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/02-\345\243\260\346\230\216\347\244\272\344\276\213/04-string/main.go" new file mode 100644 index 000000000..a57eacd99 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/02-\345\243\260\346\230\216\347\244\272\344\276\213/04-string/main.go" @@ -0,0 +1,23 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import "fmt" + +func main() { + var msg string + var name string + var text string + + fmt.Println( + msg, + name, + text, + ) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/03-\351\233\266\345\200\274/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/03-\351\233\266\345\200\274/main.go" new file mode 100644 index 000000000..3ce428638 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/03-\351\233\266\345\200\274/main.go" @@ -0,0 +1,27 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import "fmt" + +// 练习: 运行这个, 然后自己查看这些零值 (这里的 零值 指的是变量未初始化时的值, 根据类型的不同会有不同的结果, 而非字面意义上的 "0") +func main() { + var speed int // 数字类型 + var heat float64 // 数字类型 + var off bool + var brand string + + fmt.Println(speed) + fmt.Println(heat) + fmt.Println(off) + + // 我用 Printf 来打印空字符串 + // 练习: 用 Println 看看会发生什么 + fmt.Printf("%q\n", brand) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/04-\346\234\252\344\275\277\347\224\250\347\232\204\345\217\230\351\207\217\345\222\214\347\251\272\347\231\275\346\240\207\350\257\206\347\254\246/01-\346\234\252\344\275\277\347\224\250\347\232\204\345\217\230\351\207\217/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/04-\346\234\252\344\275\277\347\224\250\347\232\204\345\217\230\351\207\217\345\222\214\347\251\272\347\231\275\346\240\207\350\257\206\347\254\246/01-\346\234\252\344\275\277\347\224\250\347\232\204\345\217\230\351\207\217/main.go" new file mode 100644 index 000000000..974ede0d9 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/04-\346\234\252\344\275\277\347\224\250\347\232\204\345\217\230\351\207\217\345\222\214\347\251\272\347\231\275\346\240\207\350\257\206\347\254\246/01-\346\234\252\344\275\277\347\224\250\347\232\204\345\217\230\351\207\217/main.go" @@ -0,0 +1,20 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +// 对包级变量没有警告 +var packageLevelVar string + +func main() { + // 未使用变量错误 + // var speed int + + // 如果你使用了它, 错误就会消失 + // fmt.Println(speed) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/04-\346\234\252\344\275\277\347\224\250\347\232\204\345\217\230\351\207\217\345\222\214\347\251\272\347\231\275\346\240\207\350\257\206\347\254\246/02-\347\251\272\347\231\275\346\240\207\350\257\206\347\254\246/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/04-\346\234\252\344\275\277\347\224\250\347\232\204\345\217\230\351\207\217\345\222\214\347\251\272\347\231\275\346\240\207\350\257\206\347\254\246/02-\347\251\272\347\231\275\346\240\207\350\257\206\347\254\246/main.go" new file mode 100644 index 000000000..e82fcfe78 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/04-\346\234\252\344\275\277\347\224\250\347\232\204\345\217\230\351\207\217\345\222\214\347\251\272\347\231\275\346\240\207\350\257\206\347\254\246/02-\347\251\272\347\231\275\346\240\207\350\257\206\347\254\246/main.go" @@ -0,0 +1,17 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +func main() { + var speed int + + // 让我们把变量赋值给空白标识符 + // 这样,Go编译器就不会发脾气了 + _ = speed +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/05-\345\244\232\351\207\215\345\243\260\346\230\216/01-\345\244\232\351\207\215\345\243\260\346\230\216/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/05-\345\244\232\351\207\215\345\243\260\346\230\216/01-\345\244\232\351\207\215\345\243\260\346\230\216/main.go" new file mode 100644 index 000000000..d5b7a062b --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/05-\345\244\232\351\207\215\345\243\260\346\230\216/01-\345\244\232\351\207\215\345\243\260\346\230\216/main.go" @@ -0,0 +1,26 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import "fmt" + +func main() { + var ( + speed int + heat float64 + + off bool + brand string + ) + + fmt.Println(speed) + fmt.Println(heat) + fmt.Println(off) + fmt.Printf("%q\n", brand) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/05-\345\244\232\351\207\215\345\243\260\346\230\216/02-\345\271\263\350\241\214\345\243\260\346\230\216/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/05-\345\244\232\351\207\215\345\243\260\346\230\216/02-\345\271\263\350\241\214\345\243\260\346\230\216/main.go" new file mode 100644 index 000000000..e0c2f1032 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/05-\345\244\232\351\207\215\345\243\260\346\230\216/02-\345\271\263\350\241\214\345\243\260\346\230\216/main.go" @@ -0,0 +1,29 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import "fmt" + +func main() { + // 这等同于 + // + // var ( + // speed int + // velocity int + // ) + // + // 或者: + // + // var speed int + // var velocity int + // + var speed, velocity int + + fmt.Println(speed, velocity) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/06-\344\276\213\345\255\220/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/06-\344\276\213\345\255\220/main.go" new file mode 100644 index 000000000..22eaf91c7 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/06-\344\276\213\345\255\220/main.go" @@ -0,0 +1,42 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import "fmt" + +func main() { + // 变量名是大小写敏感的 + // MyAge, myAge 和 MYAGE 是不同的变量 + + // 使用例: + // 什么时候使用平行声明? + // + // 不好: + // var myAge int + // var yourAge int + // + // 一般: + // var ( + // myAge int + // yourAge int + // ) + // + // 推荐: + var myAge, yourAge int + fmt.Println(myAge, yourAge) + + var temperature float64 + fmt.Println(temperature) + + var success bool + fmt.Println(success) + + var language string + fmt.Println(language) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/01-int/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/01-int/main.go" new file mode 100644 index 000000000..1f6378376 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/01-int/main.go" @@ -0,0 +1,25 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +// --------------------------------------------------------- +// 练习: 声明 int +// +// 1. 声明并打印一个 int 型变量 +// +// 2. 变量名应该叫做: height +// +// 期望输出 +// 0 +// --------------------------------------------------------- + +func main() { + // var ? ? + // ? +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/01-int/solution/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/01-int/solution/main.go" new file mode 100644 index 000000000..0a8b619cc --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/01-int/solution/main.go" @@ -0,0 +1,19 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import ( + "fmt" +) + +func main() { + var height int + + fmt.Println(height) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/02-bool/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/02-bool/main.go" new file mode 100644 index 000000000..576498fea --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/02-bool/main.go" @@ -0,0 +1,25 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +// --------------------------------------------------------- +// 练习: 声明 bool +// +// 1. 声明并打印一个 bool 型变量 +// +// 2. 变量名应该叫做: isOn +// +// 期望输出 +// false +// --------------------------------------------------------- + +func main() { + // var ? ? + // ? +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/02-bool/solution/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/02-bool/solution/main.go" new file mode 100644 index 000000000..0db66eea6 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/02-bool/solution/main.go" @@ -0,0 +1,18 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import ( + "fmt" +) + +func main() { + var isOn bool + fmt.Println(isOn) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/03-float64/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/03-float64/main.go" new file mode 100644 index 000000000..236df6840 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/03-float64/main.go" @@ -0,0 +1,25 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +// --------------------------------------------------------- +// 练习: 声明 float64 +// +// 1. 声明并打印一个 float64 型变量 +// +// 2. 变量名应该叫做: brightness +// +// 期望输出 +// 0 +// --------------------------------------------------------- + +func main() { + // var ? ? + // ? +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/03-float64/solution/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/03-float64/solution/main.go" new file mode 100644 index 000000000..b6162e3f7 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/03-float64/solution/main.go" @@ -0,0 +1,19 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import ( + "fmt" +) + +func main() { + var brightness float64 + + fmt.Println(brightness) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/04-string/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/04-string/main.go" new file mode 100644 index 000000000..341de42e6 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/04-string/main.go" @@ -0,0 +1,31 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +// --------------------------------------------------------- +// 练习: 声明 string +// +// 1. 声明一个 string 型变量 +// +// 2. 打印这个变量 +// +// 期望输出 +// "" +// --------------------------------------------------------- + +func main() { + // 使用下面的代码 + // 你会在之后学习到 Printf 函数 + + // var ? + // fmt.Printf("s (%T): %q\n", s, s) + + // %T 打印变量的类型 + // %q 打印一个空字符串 +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/04-string/solution/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/04-string/solution/main.go" new file mode 100644 index 000000000..5c761a37d --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/04-string/solution/main.go" @@ -0,0 +1,16 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import "fmt" + +func main() { + var s string + fmt.Printf("s (%T): %q\n", s, s) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/05-undeclarables/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/05-undeclarables/main.go" new file mode 100644 index 000000000..0d11cd0c7 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/05-undeclarables/main.go" @@ -0,0 +1,35 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +// --------------------------------------------------------- +// 练习: 不可声明的变量 +// +// 1. 声明以下的变量 +// 3speed +// !speed +// spe?ed +// var +// func +// package +// +// 2. 观察报错信息 +// +// NOTE +// 上面这些变量的类型不重要 +// --------------------------------------------------------- + +func main() { + // var ? int + // var ? int + // var ? int + // var ? int + // var ? int + // var ? int +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/05-undeclarables/solution/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/05-undeclarables/solution/main.go" new file mode 100644 index 000000000..5a8a1f97b --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/05-undeclarables/solution/main.go" @@ -0,0 +1,18 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +func main() { + // var 3speed int + // var !speed int + // var spe?ed int + // var var int + // var func int + // var package int +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/06-with-bits/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/06-with-bits/main.go" new file mode 100644 index 000000000..d3fc14023 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/06-with-bits/main.go" @@ -0,0 +1,44 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +// --------------------------------------------------------- +// EXERCISE: 用 bit 声明 +// +// 1. 使用以下类型声明几个变量 +// int +// int8 +// int16 +// int32 +// int64 +// float32 +// float64 +// complex64 +// complex128 +// bool +// string +// rune +// byte +// +// 2. 观察他们的输出 +// +// 3. 完成后,请查看 solution +// 并阅读在那的注释 +// +// 期望输出 +// 0 0 0 0 0 0 0 (0+0i) (0+0i) false 0 0 +// "" +// --------------------------------------------------------- + +func main() { + // var i int + // var i8 int8 + + // 从这里开始继续.... +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/06-with-bits/solution/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/06-with-bits/solution/main.go" new file mode 100644 index 000000000..2747834b2 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/06-with-bits/solution/main.go" @@ -0,0 +1,46 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import "fmt" + +func main() { + // 整数类型 + var i int + var i8 int8 + var i16 int16 + var i32 int32 + var i64 int64 + + // 浮点类型 + var f32 float32 + var f64 float64 + + // 复杂类型 + var c64 complex64 + var c128 complex128 + + // 布尔型 + var b bool + + // 字符串类型 + var s string + var r rune // 同样是数字类型 + var by byte // 同样是数字类型 + + fmt.Println( + i, i8, i16, i32, i64, + f32, f64, + c64, c128, + b, r, by, + ) + + // 你也可以使用 Println 做到 + fmt.Printf("%q\n", s) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/07-multiple/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/07-multiple/main.go" new file mode 100644 index 000000000..a3d9cd5e6 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/07-multiple/main.go" @@ -0,0 +1,33 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +// --------------------------------------------------------- +// 练习: 多重声明 +// +// 1. 使用多重变量声明语句声明两个变量 +// +// 2. 第一个变量的名称应该叫 active +// 3. 第二个变量的名称应该叫 delta +// +// 4. 把它们全打印出来 +// +// HINT +// 你应该声明一个 bool 类型和一个 int 类型的变量 +// +// 期望输出 +// false 0 +// --------------------------------------------------------- + +func main() { + // var ( + // ? + // ) + // fmt.Println(active, delta) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/07-multiple/solution/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/07-multiple/solution/main.go" new file mode 100644 index 000000000..c830ace08 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/07-multiple/solution/main.go" @@ -0,0 +1,19 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import "fmt" + +func main() { + var ( + active bool + delta int + ) + fmt.Println(active, delta) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/08-multiple-2/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/08-multiple-2/main.go" new file mode 100644 index 000000000..fea716b9e --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/08-multiple-2/main.go" @@ -0,0 +1,34 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +// --------------------------------------------------------- +// 练习: 多重声明 #2 +// +// 1. 使用多重变量声明语句声明并初始化两个字符串变量 +// +// 2. 在声明变量的时候使用一次类型 +// +// 3. 第一个变量的名称应该叫 firstName +// 4. 第二个变量的名称应该叫 lastName +// +// 5. 把它们全打印出来 +// +// 期望输出 +// "" "" +// --------------------------------------------------------- + +func main() { + // 你的声明写在这里 + // + + // 使用你的变量的名称替换下面的问号 + + // fmt.Printf("%q %q\n", ?, ?) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/08-multiple-2/solution/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/08-multiple-2/solution/main.go" new file mode 100644 index 000000000..b73f328f7 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/08-multiple-2/solution/main.go" @@ -0,0 +1,16 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import "fmt" + +func main() { + var firstName, lastName string = "", "" + fmt.Printf("%q %q\n", firstName, lastName) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/09-unused/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/09-unused/main.go" new file mode 100644 index 000000000..d2bf3ca83 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/09-unused/main.go" @@ -0,0 +1,25 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +// --------------------------------------------------------- +// 练习: 未使用的 +// +// 1. 声明一个变量 +// +// 2. 变量的名称应该叫: isLiquid +// +// 3. 使用空白标识符丢弃它 +// +// NOTE +// 不要打印这个变量 +// --------------------------------------------------------- + +func main() { +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/09-unused/solution/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/09-unused/solution/main.go" new file mode 100644 index 000000000..9a1dac5e5 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/09-unused/solution/main.go" @@ -0,0 +1,14 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +func main() { + var isLiquid bool + _ = isLiquid +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/10-package-variable/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/10-package-variable/main.go" new file mode 100644 index 000000000..760433216 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/10-package-variable/main.go" @@ -0,0 +1,20 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +// --------------------------------------------------------- +// 练习: 包变量 +// +// 1. 在包作用域内声明一个变量 +// +// 2. 观察当你不使用它时是否会发生一些事情 +// --------------------------------------------------------- + +func main() { +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/10-package-variable/solution/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/10-package-variable/solution/main.go" new file mode 100644 index 000000000..2e07567a0 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/10-package-variable/solution/main.go" @@ -0,0 +1,14 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +var isLiquid bool + +func main() { +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/11-wrong-doer/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/11-wrong-doer/main.go" new file mode 100644 index 000000000..aa53fedba --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/11-wrong-doer/main.go" @@ -0,0 +1,28 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +// --------------------------------------------------------- +// EXERCISE: 做错事的人 +// +// 1. 打印一个变量 +// +// 2. 然后声明它 +// (意思是: 试着在它的声明前打印它) +// +// 3. 观察报错 +// --------------------------------------------------------- + +func main() { + // 先打印它: + // fmt.Println(?) + + // 然后声明它: + // var ? ? +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/11-wrong-doer/solution/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/11-wrong-doer/solution/main.go" new file mode 100644 index 000000000..ae9269776 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/11-wrong-doer/solution/main.go" @@ -0,0 +1,16 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +func main() { + // 去掉下面代码的注释来查看报错 + + // fmt.Println(age) + // var age int +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/README.md" "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/README.md" new file mode 100644 index 000000000..373119341 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\347\273\203\344\271\240/README.md" @@ -0,0 +1,25 @@ +# 声明并打印变量 + +热身。声明几个变量,获得一些经验。熟悉变量声明的语法。 + +1. **[声明 int](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/02-声明/练习/01-int)** + +2. **[声明 bool](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/02-声明/练习/02-bool)** + +3. **[声明 float64](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/02-声明/练习/03-float64)** + +4. **[声明 string](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/02-声明/练习/04-string)** + +5. **[声明 不可声明的变量](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/02-声明/练习/05-undeclarables)** + +6. **[使用 bits 声明变量](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/02-声明/练习/translation/chinese/06-with-bits)** + +7. **[多重声明](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/02-声明/练习/07-multiple)** + +8. **[多重声明 2](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/02-声明/练习/08-multiple-2)** + +9. **[声明一个未使用的变量](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/02-声明/练习/09-unused)** + +10. **[声明一个包变量](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/02-声明/练习/10-package-variable)** + +11. **[在声明前使用](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/02-声明/练习/11-wrong-doer)** diff --git "a/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\351\227\256\351\242\230/01-what/README.md" "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\351\227\256\351\242\230/01-what/README.md" new file mode 100644 index 000000000..2c9d61f17 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\351\227\256\351\242\230/01-what/README.md" @@ -0,0 +1,25 @@ +# 问题: 什么是变量? + +## 变量“住”在哪里? + +* 硬盘 +* 内存 - *正确* +* CPU + +## 你使用变量名来做什么? + +* 为了以后能够访问它 - *正确* +* 这只是一个标签 +* 我不需要使用它。 + +## 如何改变一个变量的值? + +* 通过变量名 - *正确* +* 通过变量值 +* 通过向 Go 要求 + +## 在变量声明之后,你可以改变变量的类型吗?? + +* 可以 : Go 是动态类型 +* 不行 : Go 是静态类型 - *正确* +* 两者都有: Go 支持两者 \ No newline at end of file diff --git "a/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\351\227\256\351\242\230/02-declaration/README.md" "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\351\227\256\351\242\230/02-declaration/README.md" new file mode 100644 index 000000000..36920112b --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\351\227\256\351\242\230/02-declaration/README.md" @@ -0,0 +1,25 @@ +## 你需要使用哪条语句来声明变量? + +* name int +* vars string name +* var name integer +* var width int *正确* + +## 下面哪句话是正确的? + +* 你可以在声明一个变量之前使用它 +* 在使用一个变量之前,你必须先声明它 *正确* + +## Go 是什么类型的语言? + +* 弱类型 +* 动态类型 +* 强类型 *正确* +* 自由类型 + +## 下面哪个变量名是正确的? + +* int +* four *正确* +* 2computers +* one?there \ No newline at end of file diff --git "a/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\351\227\256\351\242\230/03-unused-variables/README.md" "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\351\227\256\351\242\230/03-unused-variables/README.md" new file mode 100644 index 000000000..b4036c34a --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\351\227\256\351\242\230/03-unused-variables/README.md" @@ -0,0 +1,18 @@ +## 当你不使用一个块作用域中声明的变量会发生什么? + +* 什么都不会发生, 它会正常工作 +* 它将被自动删除 +* 程序无法编译 *正确* + +## 当你不使用一个包作用域中声明的变量会发生什么? + +* 什么都不会发生, 它会正常工作 *正确* +* 它将被自动删除 +* 程序无法编译 + +## 如何防止未使用变量的错误? + +* 你可以改变变量的名称 +* 你可以使用空白标识符来避免它 *正确* +* 你可以改变变量的类型 + diff --git "a/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\351\227\256\351\242\230/04-zero-values/README.md" "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\351\227\256\351\242\230/04-zero-values/README.md" new file mode 100644 index 000000000..48819a562 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/02-\345\243\260\346\230\216/\351\227\256\351\242\230/04-zero-values/README.md" @@ -0,0 +1,27 @@ +## 哪种变量类型的零值是 0? + +- bool +- pointer +- string +- 所有的数字类型 *正确* + +## 哪种变量类型的零值是 false? + +- bool *正确* +- pointer +- string +- 所有的数字类型 + +## 哪种变量类型的零值是 ""? + +- bool +- pointer +- string *正确* +- 所有的数字类型 + +## 哪种变量类型的零值是 nil? + +- bool +- pointer *正确* +- string +- 所有的数字类型 \ No newline at end of file diff --git "a/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/01-\345\210\235\345\247\213\345\214\226\344\273\245\345\217\212\347\256\200\347\237\255\345\243\260\346\230\216/01-\345\210\235\345\247\213\345\214\226/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/01-\345\210\235\345\247\213\345\214\226\344\273\245\345\217\212\347\256\200\347\237\255\345\243\260\346\230\216/01-\345\210\235\345\247\213\345\214\226/main.go" new file mode 100644 index 000000000..07f78f2a9 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/01-\345\210\235\345\247\213\345\214\226\344\273\245\345\217\212\347\256\200\347\237\255\345\243\260\346\230\216/01-\345\210\235\345\247\213\345\214\226/main.go" @@ -0,0 +1,26 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import "fmt" + +func main() { + // = 是赋值操作符 + // 当在一个变量声明中使用时,它将该变量初始化为给定的值 + + // 在这, Go 将 safe 变量初始化为 true + + // 方案 #1(方案 #2 更好) + // var safe bool = true + + // 方案 #2 + var safe = true + + fmt.Println(safe) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/01-\345\210\235\345\247\213\345\214\226\344\273\245\345\217\212\347\256\200\347\237\255\345\243\260\346\230\216/02-\347\256\200\347\237\255\345\243\260\346\230\216/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/01-\345\210\235\345\247\213\345\214\226\344\273\245\345\217\212\347\256\200\347\237\255\345\243\260\346\230\216/02-\347\256\200\347\237\255\345\243\260\346\230\216/main.go" new file mode 100644 index 000000000..812bde46e --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/01-\345\210\235\345\247\213\345\214\226\344\273\245\345\217\212\347\256\200\347\237\255\345\243\260\346\230\216/02-\347\256\200\347\237\255\345\243\260\346\230\216/main.go" @@ -0,0 +1,35 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import "fmt" + +func main() { + // 方案 #1(方案 #2 更好) + // var safe bool = true + + // 方案 #2 (还行) + // var safe = true + + // 方案 #3 - 简短声明 (最佳) + // + // 你甚至不需要输入 var 关键词 + // + // 简短声明等同于: + // var safe bool = true + // var safe = true + // + // Go从初始值中获取(推断)类型 + // + // true 的默认类型是 bool + // 所以,变量 safe 的类型变成了 bool + safe := true + + fmt.Println(safe) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/01-\345\210\235\345\247\213\345\214\226\344\273\245\345\217\212\347\256\200\347\237\255\345\243\260\346\230\216/03-\347\274\226\347\240\201\347\244\272\344\276\213/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/01-\345\210\235\345\247\213\345\214\226\344\273\245\345\217\212\347\256\200\347\237\255\345\243\260\346\230\216/03-\347\274\226\347\240\201\347\244\272\344\276\213/main.go" new file mode 100644 index 000000000..b4ae04d38 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/01-\345\210\235\345\247\213\345\214\226\344\273\245\345\217\212\347\256\200\347\237\255\345\243\260\346\230\216/03-\347\274\226\347\240\201\347\244\272\344\276\213/main.go" @@ -0,0 +1,39 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import "fmt" + +func main() { + // var name string = "Carl" + // var name = "Carl" + name := "Carl" + + // var isScientist bool = true + // var isScientist = true + isScientist := true + + // var age int = 62 + // var age = 62 + age := 62 + + // var degree float64 = 5. + // var degree = 5. + degree := 5. + + fmt.Println(name, isScientist, age, degree) + + // 类型推断也适用于变量 + // + // Go 获取变量的类型并将其分配给新声明的变量 + // + // 现在name2变量的类型也是 `string` + name2 := name + fmt.Println(name2) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/02-\345\214\205\344\275\234\347\224\250\345\237\237/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/02-\345\214\205\344\275\234\347\224\250\345\237\237/main.go" new file mode 100644 index 000000000..364c661f3 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/02-\345\214\205\344\275\234\347\224\250\345\237\237/main.go" @@ -0,0 +1,30 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import "fmt" + +// 你不能使用没有关键字的声明语句 +// 简短声明没有关键字 (`var`) +// 所以, 它不能在包作用域上使用 +// +// 语法错误: +// "函数体外的非声明语句" +// 原文: +// SYNTAX ERROR: +// "non-declaration statement outside function body" + +// safe := true + +// 然而, 你可以在包作用域上正常声明一个变量, 因为它有关键词: `var` +var safe = true + +func main() { + fmt.Println(safe) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/03-\345\244\232\351\207\215\347\256\200\347\237\255\345\243\260\346\230\216/01-\345\243\260\346\230\216/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/03-\345\244\232\351\207\215\347\256\200\347\237\255\345\243\260\346\230\216/01-\345\243\260\346\230\216/main.go" new file mode 100644 index 000000000..b5d4ca60e --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/03-\345\244\232\351\207\215\347\256\200\347\237\255\345\243\260\346\230\216/01-\345\243\260\346\230\216/main.go" @@ -0,0 +1,22 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import "fmt" + +func main() { + // the number of variables and values should be equal + + // -> `true` is being assigned to `safe` + // -> `50` is being assigned to `speed` + + safe, speed := true, 50 + + fmt.Println(safe, speed) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/03-\345\244\232\351\207\215\347\256\200\347\237\255\345\243\260\346\230\216/02-\347\274\226\347\240\201\347\244\272\344\276\213/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/03-\345\244\232\351\207\215\347\256\200\347\237\255\345\243\260\346\230\216/02-\347\274\226\347\240\201\347\244\272\344\276\213/main.go" new file mode 100644 index 000000000..9aac71a99 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/03-\345\244\232\351\207\215\347\256\200\347\237\255\345\243\260\346\230\216/02-\347\274\226\347\240\201\347\244\272\344\276\213/main.go" @@ -0,0 +1,32 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import "fmt" + +func main() { + name, lastname := "Nikola", "Tesla" + fmt.Println(name, lastname) + + birth, death := 1856, 1943 + fmt.Println(birth, death) + + on, off := true, false + fmt.Println(on, off) + + // 这里没有限制 + // 然而, 随着你声明变量数量的增多, 代码的可读性会越来越差 + degree, ratio, heat := 10.55, 30.5, 20. + fmt.Println(degree, ratio, heat) + + // 你可以简短声明不同的变量类型 + nFiles, valid, msg := 10, true, "hello" + + fmt.Println(nFiles, valid, msg) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/03-\345\244\232\351\207\215\347\256\200\347\237\255\345\243\260\346\230\216/03-\351\207\215\345\243\260\346\230\216/01/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/03-\345\244\232\351\207\215\347\256\200\347\237\255\345\243\260\346\230\216/03-\351\207\215\345\243\260\346\230\216/01/main.go" new file mode 100644 index 000000000..9798e9e43 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/03-\345\244\232\351\207\215\347\256\200\347\237\255\345\243\260\346\230\216/03-\351\207\215\345\243\260\346\230\216/01/main.go" @@ -0,0 +1,34 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import "fmt" + +func main() { + // `safe` 的值是 `false` + var safe bool + + // `safe` 的值现在是 `true` + + // `speed` 被声明并初始化成了 `50` + + // 只在以下情况下能进行重声明 + // + // 至少一个重声明的变量是新变量 + + safe, speed := true, 50 + + fmt.Println(safe, speed) + + // 练习 + // + // 在"再次"简短声明前声明变量 speed ( 即在重声明语句前声明 speed 变量 ) + // + // Observe what happens +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/03-\345\244\232\351\207\215\347\256\200\347\237\255\345\243\260\346\230\216/03-\351\207\215\345\243\260\346\230\216/02-\347\274\226\347\240\201\347\244\272\344\276\213/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/03-\345\244\232\351\207\215\347\256\200\347\237\255\345\243\260\346\230\216/03-\351\207\215\345\243\260\346\230\216/02-\347\274\226\347\240\201\347\244\272\344\276\213/main.go" new file mode 100644 index 000000000..b11f1da8c --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/03-\345\244\232\351\207\215\347\256\200\347\237\255\345\243\260\346\230\216/03-\351\207\215\345\243\260\346\230\216/02-\347\274\226\347\240\201\347\244\272\344\276\213/main.go" @@ -0,0 +1,42 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import "fmt" + +func main() { + // 例 #1 + + name := "Nikola" + fmt.Println(name) + + // name 已经在代码块里存在了 + // name := "Marie" + + // 给 name 赋了一个新值 + // 并且声明一个新变量 age 并赋值 66 + name, age := "Marie", 66 + fmt.Println(name, age) + + // 例 #2 + + // name = "Albert" + // birth := 1879 + + // 下面的重声明等同于上面的语句. + // + // `name` 是一个已经存在的变量 + // Go 给变量 name 赋值了 "Albert" + // + // `birth` 是一个新变量 + // Go 声明并给它赋值了 `1879` + name, birth := "Albert", 1879 + + fmt.Println(name, birth) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/04-\347\256\200\347\237\255-vs-\346\255\243\345\270\270/01-\345\243\260\346\230\216/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/04-\347\256\200\347\237\255-vs-\346\255\243\345\270\270/01-\345\243\260\346\230\216/main.go" new file mode 100644 index 000000000..3ab660e4e --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/04-\347\256\200\347\237\255-vs-\346\255\243\345\270\270/01-\345\243\260\346\230\216/main.go" @@ -0,0 +1,42 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +// 正常声明的使用例 + +// ----------------------------------------------------- +// 当你需要一个包作用域变量时 +// ----------------------------------------------------- + +// version := 0 // 不能这样 +var version int + +func main() { + + // ----------------------------------------------------- + // 如果你不知道初始值时 + // ----------------------------------------------------- + + // 别这样做: + // score := 0 + + // 这样做: + // var score int + + // ----------------------------------------------------- + // 对变量进行分组以提高可读性 + // ----------------------------------------------------- + + // var ( + // video string + + // duration int + // current int + // ) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/04-\347\256\200\347\237\255-vs-\346\255\243\345\270\270/02-\347\256\200\347\237\255\345\243\260\346\230\216/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/04-\347\256\200\347\237\255-vs-\346\255\243\345\270\270/02-\347\256\200\347\237\255\345\243\260\346\230\216/main.go" new file mode 100644 index 000000000..9a3c74b32 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/04-\347\256\200\347\237\255-vs-\346\255\243\345\270\270/02-\347\256\200\347\237\255\345\243\260\346\230\216/main.go" @@ -0,0 +1,35 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +// 简短声明的使用例 + +func main() { + + // ----------------------------------------------------- + // 如果你知道初始值 + // ----------------------------------------------------- + + // 别这样做: + // var width, height = 100, 50 + + // 这样做 (简洁): + // width, height := 100, 50 + + // ----------------------------------------------------- + // 重声明 + // ----------------------------------------------------- + + // 别这样做: + // width = 50 + // color := red + + // 这样做 (简洁): + // width, color := 50, "red" +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/\347\273\203\344\271\240/01-short-declare/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/\347\273\203\344\271\240/01-short-declare/main.go" new file mode 100644 index 000000000..df9810634 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/\347\273\203\344\271\240/01-short-declare/main.go" @@ -0,0 +1,32 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +// --------------------------------------------------------- +// 练习: 简短声明 +// +// 声明并打印四个变量,使用简短声明语句 +// +// 期望输出 +// i: 314 f: 3.14 s: Hello b: true +// --------------------------------------------------------- + +func main() { + // 在这里写下你的声明语句 + // + + // 然后去掉下面代码的注释 + + // fmt.Println( + // "i:", i, + // "f:", f, + // "s:", s, + // "b:", b, + // ) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/\347\273\203\344\271\240/01-short-declare/solution/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/\347\273\203\344\271\240/01-short-declare/solution/main.go" new file mode 100644 index 000000000..1b74bf14b --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/\347\273\203\344\271\240/01-short-declare/solution/main.go" @@ -0,0 +1,27 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import ( + "fmt" +) + +func main() { + i := 314 + f := 3.14 + s := "Hello" + b := true + + fmt.Println( + "i:", i, + "f:", f, + "s:", s, + "b:", b, + ) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/\347\273\203\344\271\240/02-multiple-short-declare/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/\347\273\203\344\271\240/02-multiple-short-declare/main.go" new file mode 100644 index 000000000..7fb9fbcaf --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/\347\273\203\344\271\240/02-multiple-short-declare/main.go" @@ -0,0 +1,27 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +// --------------------------------------------------------- +// 练习: 多重简短声明 +// +// 使用多重简短声明语句声明两个变量 +// +// 期望输出 +// 14 true +// --------------------------------------------------------- + +func main() { + // 在这里写下你的声明语句 + // + + // 然后去掉下面代码的注释 + + // fmt.Println(a, b) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/\347\273\203\344\271\240/02-multiple-short-declare/solution/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/\347\273\203\344\271\240/02-multiple-short-declare/solution/main.go" new file mode 100644 index 000000000..f0e65f7d6 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/\347\273\203\344\271\240/02-multiple-short-declare/solution/main.go" @@ -0,0 +1,19 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import ( + "fmt" +) + +func main() { + a, b := 14, true + + fmt.Println(a, b) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/\347\273\203\344\271\240/03-multiple-short-declare-2/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/\347\273\203\344\271\240/03-multiple-short-declare-2/main.go" new file mode 100644 index 000000000..2b5d5222d --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/\347\273\203\344\271\240/03-multiple-short-declare-2/main.go" @@ -0,0 +1,30 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +// --------------------------------------------------------- +// 练习: 多重简短声明 #2 +// +// 1. 使用多重简短声明语句声明两个变量 +// +// 2. 变量 `a` 的值应该是 42 +// 3. 变量 `c` 的值应该是 "good" +// +// 期望输出 +// 42 good +// --------------------------------------------------------- + +func main() { + // 在这里写下你的声明语句 + // + + // 然后去掉下面代码的注释 + + // fmt.Println(a, c) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/\347\273\203\344\271\240/03-multiple-short-declare-2/solution/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/\347\273\203\344\271\240/03-multiple-short-declare-2/solution/main.go" new file mode 100644 index 000000000..85c399d00 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/\347\273\203\344\271\240/03-multiple-short-declare-2/solution/main.go" @@ -0,0 +1,19 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import ( + "fmt" +) + +func main() { + a, c := 42, "good" + + fmt.Println(a, c) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/\347\273\203\344\271\240/04-short-with-expression/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/\347\273\203\344\271\240/04-short-with-expression/main.go" new file mode 100644 index 000000000..f40ab36c3 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/\347\273\203\344\271\240/04-short-with-expression/main.go" @@ -0,0 +1,28 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +// --------------------------------------------------------- +// 练习: 简短表达式 +// +// 1. 间断声明一个变量 `sum` +// +// 2. 用一个 27 和 3.5 相加的语句初始化它的值 +// +// 期望输出 +// 30.5 +// --------------------------------------------------------- + +func main() { + // 在这里写下你的声明语句 + // + + // 然后去掉下面代码的注释 + // fmt.Println(sum) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/\347\273\203\344\271\240/04-short-with-expression/solution/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/\347\273\203\344\271\240/04-short-with-expression/solution/main.go" new file mode 100644 index 000000000..02c76c5ce --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/\347\273\203\344\271\240/04-short-with-expression/solution/main.go" @@ -0,0 +1,19 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import ( + "fmt" +) + +func main() { + sum := 27 + 3.5 + + fmt.Println(sum) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/\347\273\203\344\271\240/05-short-discard/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/\347\273\203\344\271\240/05-short-discard/main.go" new file mode 100644 index 000000000..fb47a6f83 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/\347\273\203\344\271\240/05-short-discard/main.go" @@ -0,0 +1,35 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +// --------------------------------------------------------- +// 练习: 简短丢弃 +// +// 1. 简短声明两个 bool 变量 +// (使用多重简短声明语法) +// +// 2. 初始化两个变量为 true +// +// 3. 改变你的声明并使用空白标识符 +// 丢弃第二个变量的值 +// +// 4. 仅打印第一个变量 +// +// 期望输出 +// true +// --------------------------------------------------------- + +func main() { + // 在这里写下你的声明语句 + // + + // 然后去掉下面代码的注释 + + // fmt.Println(on) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/\347\273\203\344\271\240/05-short-discard/solution/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/\347\273\203\344\271\240/05-short-discard/solution/main.go" new file mode 100644 index 000000000..35c2c33d9 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/\347\273\203\344\271\240/05-short-discard/solution/main.go" @@ -0,0 +1,21 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import ( + "fmt" +) + +func main() { + // 你可以在简短的声明中舍弃数值 + + on, _ := true, true + + fmt.Println(on) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/\347\273\203\344\271\240/06-redeclare/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/\347\273\203\344\271\240/06-redeclare/main.go" new file mode 100644 index 000000000..d2bb6dbf8 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/\347\273\203\344\271\240/06-redeclare/main.go" @@ -0,0 +1,35 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +// --------------------------------------------------------- +// 练习: 重声明 +// +// 1. 短声明两个 int 变量:age 和 yourAge +// (使用多重简短声明语法) +// +// 2. 声明一个新的 float 类型变量 ratio +// 修改变量 'age' 的值为 42 +// +// (! 你应该用重声明) +// +// 4. 打印所有变量 +// +// 期望输出 +// 42, 20, 3.14 +// --------------------------------------------------------- + +func main() { + // 在这里写下你的声明语句 + // + + // 然后去掉下面代码的注释 + + // fmt.Println(age, yourAge, ratio) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/\347\273\203\344\271\240/06-redeclare/solution/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/\347\273\203\344\271\240/06-redeclare/solution/main.go" new file mode 100644 index 000000000..fa94a4e90 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/\347\273\203\344\271\240/06-redeclare/solution/main.go" @@ -0,0 +1,20 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import ( + "fmt" +) + +func main() { + age, yourAge := 10, 20 + age, ratio := 42, 3.14 + + fmt.Println(age, yourAge, ratio) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/\347\273\203\344\271\240/README.md" "b/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/\347\273\203\344\271\240/README.md" new file mode 100644 index 000000000..08d67a24f --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/\347\273\203\344\271\240/README.md" @@ -0,0 +1,15 @@ +# 简短声明 + +是时候使用简短的声明语法来声明一些变量了。除此之外还有重声明变量以及丢弃变量。 + +1. **[简短声明](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/03-简短声明/练习/01-short-declare)** + +2. **[多重简短声明](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/03-简短声明/练习/02-multiple-short-declare)** + +3. **[多重简短声明 #2](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/03-简短声明/练习/03-multiple-short-declare-2)** + +4. **[简短表达式](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/03-简短声明/练习/04-short-with-expression)** + +5. **[简短丢弃](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/03-简短声明/练习/05-short-discard)** + +6. **[重声明](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/03-简短声明/练习/06-redeclare)** \ No newline at end of file diff --git "a/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/\351\227\256\351\242\230/README.md" "b/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/\351\227\256\351\242\230/README.md" new file mode 100644 index 000000000..0e35371b6 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/03-\347\256\200\347\237\255\345\243\260\346\230\216/\351\227\256\351\242\230/README.md" @@ -0,0 +1,101 @@ +## 哪个是正确的声明? +* var int safe := 3 +* var safe bool := 3 +* safe := true *正确* + +## 哪个是正确的声明? +* var short := true +* int num := 1 +* speed := 50 *正确* +* num int := 2 + +## 哪个是正确的声明? +* x, y, z := 10, 20 +* x = 10, +* y, x, p := 5, "hi", 1.5 *正确* +* y, x = "hello", 10 + +## 哪个声明和下面的声明等价? +```go +var s string = "hi" +``` + +* var s int = "hi" +* s := "hi" *正确* +* s, p := 2, 3 + +## 哪个声明和下面的声明等价? +```go +var n = 10 +``` + +* n := 10.0 +* m, n := 1, 0 +* var n int = 10 *正确* + +## 变量 `s` 的类型是什么? +```go +s := "hmm..." +``` + +* bool +* string *正确* +* int +* float64 + +## 变量 `b` 的类型是什么? +```go +b := true +``` + +* bool *正确* +* string +* int +* float64 + +## 变量 `i` 的类型是什么? +```go +i := 42 +``` + +* bool +* string +* int *正确* +* float64 + +## 变量 `f` 的类型是什么? +```go +f := 6.28 +``` + +* bool +* string +* int +* float64 *正确* + +## 变量 `x` 的类型是什么? + +```go +y, x := false, 20 +``` + +* 10 +* 20 *正确* +* false + +## 变量 `x` 的类型是什么? + +```go +y, x := false, 20 +x, z := 10, "hi" +``` + +* 10 *正确* +* 20 +* false + +## 下面哪个声明能在包作用域上使用? + +* x := 10 +* y, x := 10, 5 +* var x, y = 5, 10 *正确* diff --git "a/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/01-\346\246\202\350\277\260/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/01-\346\246\202\350\277\260/main.go" new file mode 100644 index 000000000..5a1c50863 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/01-\346\246\202\350\277\260/main.go" @@ -0,0 +1,27 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import "fmt" + +func main() { + var counter int + + fmt.Println("counter's name : counter") + fmt.Println("counter's value:", counter) + fmt.Printf("counter's type : %T\n", counter) + + counter = 10 // OK + // counter = "ten" // NOT OK + + fmt.Println("counter's value:", counter) + + counter++ + fmt.Println("counter's value:", counter) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/01-\350\265\213\345\200\274/01-\350\265\213\345\200\274/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/01-\350\265\213\345\200\274/01-\350\265\213\345\200\274/main.go" new file mode 100644 index 000000000..421503ad7 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/01-\350\265\213\345\200\274/01-\350\265\213\345\200\274/main.go" @@ -0,0 +1,22 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import "fmt" + +func main() { + var speed int + fmt.Println(speed) + + speed = 100 + fmt.Println(speed) + + speed = speed - 25 + fmt.Println(speed) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/01-\350\265\213\345\200\274/02-\345\274\272\347\261\273\345\236\213/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/01-\350\265\213\345\200\274/02-\345\274\272\347\261\273\345\236\213/main.go" new file mode 100644 index 000000000..70e8c6bf3 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/01-\350\265\213\345\200\274/02-\345\274\272\347\261\273\345\236\213/main.go" @@ -0,0 +1,33 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +// Go 是一个强类型的编程语言 + +// 即使是 浮点 (float) 和 整数 (int) 也是不同的类型 +// 甚至: int32 和 int 也是不同的类型 + +// 练习: 尝试去掉注释并观察错误 + +func main() { + var speed int + // speed = "100" + + var running bool + // running = 1 + + var force float64 + // speed = force + + // Go 自动将无标注的 int 转换为 float64 + force = 1 + + // 让编译器开心 + _, _, _ = speed, running, force +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/01-\350\265\213\345\200\274/03-\344\276\213\345\255\220/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/01-\350\265\213\345\200\274/03-\344\276\213\345\255\220/main.go" new file mode 100644 index 000000000..8e262faf7 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/01-\350\265\213\345\200\274/03-\344\276\213\345\255\220/main.go" @@ -0,0 +1,51 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import "fmt" + +func main() { + var ( + name string + age int + famous bool + ) + + // Example #1 + name = "Newton" + age = 84 + famous = true + + fmt.Println(name, age, famous) + + // Example #2 + name = "Somebody" + age = 20 + famous = false + + fmt.Println(name, age, famous) + + // Example #3 + // EXERCISE: Why this doesn't work? Think about it. + + // name = 20 + // name = age + + // save the previous value of the variable + // to a new variable + var prevName string + prevName = name + + // overwrite the value of the original variable + // by assigning to it + name = "Einstein" + + fmt.Println("previous name:", prevName) + fmt.Println("current name :", name) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/05-\345\244\232\351\207\215\350\265\213\345\200\274/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/05-\345\244\232\351\207\215\350\265\213\345\200\274/main.go" new file mode 100644 index 000000000..61269f4b5 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/05-\345\244\232\351\207\215\350\265\213\345\200\274/main.go" @@ -0,0 +1,30 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import ( + "fmt" + "time" +) + +func main() { + var ( + speed int + now time.Time + ) + + speed, now = 100, time.Now() + + fmt.Println(speed, now) + + // 练习: + // 尝试用这个替代式 (格式化时间). + + // fmt.Println(speed, now.Format(time.Kitchen)) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/06-\344\272\244\346\215\242/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/06-\344\272\244\346\215\242/main.go" new file mode 100644 index 000000000..c4019c0d8 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/06-\344\272\244\346\215\242/main.go" @@ -0,0 +1,22 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import "fmt" + +func main() { + var ( + speed = 100 + prevSpeed = 50 + ) + + speed, prevSpeed = prevSpeed, speed + + fmt.Println(speed, prevSpeed) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/07-\350\267\257\345\276\204/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/07-\350\267\257\345\276\204/main.go" new file mode 100644 index 000000000..f45d35a2a --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/07-\350\267\257\345\276\204/main.go" @@ -0,0 +1,23 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import ( + "fmt" + "path" +) + +func main() { + var dir, file string + + dir, file = path.Split("css/main.css") + + fmt.Println("dir :", dir) + fmt.Println("file:", file) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/08-\350\267\257\345\276\204\344\270\242\345\274\203/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/08-\350\267\257\345\276\204\344\270\242\345\274\203/main.go" new file mode 100644 index 000000000..5eb0f8fdc --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/08-\350\267\257\345\276\204\344\270\242\345\274\203/main.go" @@ -0,0 +1,22 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import ( + "fmt" + "path" +) + +func main() { + var file string + + _, file = path.Split("css/main.css") + + fmt.Println("file:", file) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/09-\350\267\257\345\276\204\347\256\200\347\237\255\345\243\260\346\230\216/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/09-\350\267\257\345\276\204\347\256\200\347\237\255\345\243\260\346\230\216/main.go" new file mode 100644 index 000000000..7c69e8868 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/09-\350\267\257\345\276\204\347\256\200\347\237\255\345\243\260\346\230\216/main.go" @@ -0,0 +1,23 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import ( + "fmt" + "path" +) + +func main() { + _, file := path.Split("css/main.css") + + // 或者这样: + // dir, file := path.Split("css/main.css") + + fmt.Println("file:", file) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/\347\273\203\344\271\240/01-make-it-blue/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/\347\273\203\344\271\240/01-make-it-blue/main.go" new file mode 100644 index 000000000..82608e186 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/\347\273\203\344\271\240/01-make-it-blue/main.go" @@ -0,0 +1,31 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +// --------------------------------------------------------- +// 练习: 让它变蓝 +// +// 1. 修改 `color` 变量的值为 "blue" +// +// 2. 打印它 +// +// 期望输出 +// blue +// --------------------------------------------------------- + +func main() { + // 去掉下面代码的注释: + + // color := "green" + + // 在下面写上你的代码: + + // ? + +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/\347\273\203\344\271\240/01-make-it-blue/solution/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/\347\273\203\344\271\240/01-make-it-blue/solution/main.go" new file mode 100644 index 000000000..9089ae95f --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/\347\273\203\344\271\240/01-make-it-blue/solution/main.go" @@ -0,0 +1,19 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import "fmt" + +func main() { + color := "green" + + color = "blue" + + fmt.Println(color) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/\347\273\203\344\271\240/02-vars-to-vars/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/\347\273\203\344\271\240/02-vars-to-vars/main.go" new file mode 100644 index 000000000..aa7a6f00b --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/\347\273\203\344\271\240/02-vars-to-vars/main.go" @@ -0,0 +1,50 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +// --------------------------------------------------------- +// 练习: 变量到变量 +// +// 1. 修改 `color` 变量的值为 "dark green" +// +// 2. 不要直接将 "dark green" 赋值给 `color` +// +// 相反的, 在赋值时再次使用 `color` 变量 (即在赋值表达式中再次用到 `color`) +// +// 3. 打印它 +// +// 限制 +// 错误的答案, 别像这样做: +// `color = "dark green"` +// +// 提示 +// + 操作符可以串联字符串的值 +// +// 例子: +// +// "h" + "e" + "y" 返回 "hey" +// +// 期望输出 +// dark green +// --------------------------------------------------------- + +func main() { + // 去掉下面代码的注释: + + // color := "green" + + // 在下面写上你的代码: + + // ? + + // 去掉下面代码的注释以打印变量 + + // fmt.Println(color) + +} \ No newline at end of file diff --git "a/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/\347\273\203\344\271\240/02-vars-to-vars/solution/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/\347\273\203\344\271\240/02-vars-to-vars/solution/main.go" new file mode 100644 index 000000000..6b3610084 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/\347\273\203\344\271\240/02-vars-to-vars/solution/main.go" @@ -0,0 +1,21 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import "fmt" + +func main() { + color := "green" + + // `"dark " + color` 是一个表达式 + + color = "dark " + color + + fmt.Println(color) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/\347\273\203\344\271\240/03-assign-with-expressions/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/\347\273\203\344\271\240/03-assign-with-expressions/main.go" new file mode 100644 index 000000000..e9bf63ce7 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/\347\273\203\344\271\240/03-assign-with-expressions/main.go" @@ -0,0 +1,41 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import "fmt" + +// --------------------------------------------------------- +// 练习: 用表达式赋值 +// +// 1. 用 3.14 乘 2 并赋值到变量 `n` +// +// 2. 打印 `n` +// +// 提示 +// 例子: 3 * 2 = 6 +// * 是乘法操作符 (它使数字相乘) +// +// 期望输出 +// 6.28 +// --------------------------------------------------------- + +func main() { + // 别修改这里 + + // 声明一个新的 float64 变量 + // 0. 代表 0.0 + n := 0. + + // 在下面写上你的代码: + + // ? + + fmt.Println(n) + +} \ No newline at end of file diff --git "a/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/\347\273\203\344\271\240/03-assign-with-expressions/solution/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/\347\273\203\344\271\240/03-assign-with-expressions/solution/main.go" new file mode 100644 index 000000000..2a854cc95 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/\347\273\203\344\271\240/03-assign-with-expressions/solution/main.go" @@ -0,0 +1,19 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import "fmt" + +func main() { + n := 0. + + n = 3.14 * 2 + + fmt.Println(n) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/\347\273\203\344\271\240/04-find-the-rectangle-perimeter/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/\347\273\203\344\271\240/04-find-the-rectangle-perimeter/main.go" new file mode 100644 index 000000000..d7203d170 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/\347\273\203\344\271\240/04-find-the-rectangle-perimeter/main.go" @@ -0,0 +1,45 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +// --------------------------------------------------------- +// 练习: 找到矩形的周长 +// +// 1. 找到矩形的周长 +// 宽为 5 +// 高为 6 +// +// 2. 把结果复制到 `perimeter` 变量上 +// +// 3. 打印 `perimeter` +// +// 提示 +// 公式 = 2 × (宽 + 高) +// +// 期望输出 +// 22 +// +// 附加题 +// 在这里找到更多的公式,并在新的程序中计算它们 +// https://www.mathsisfun.com/area.html +// --------------------------------------------------------- + +func main() { + // 去掉下面代码的注释 + + // var ( + // perimeter int + // width, height = 5, 6 + // ) + + // 计算结果时使用上述变量 + + // 在下面写上你的代码: + +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/\347\273\203\344\271\240/04-find-the-rectangle-perimeter/solution/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/\347\273\203\344\271\240/04-find-the-rectangle-perimeter/solution/main.go" new file mode 100644 index 000000000..d0546badc --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/\347\273\203\344\271\240/04-find-the-rectangle-perimeter/solution/main.go" @@ -0,0 +1,27 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import "fmt" + +func main() { + var ( + perimeter int + width, height = 5, 6 + ) + + // 首先计算: (宽 + 高) + // 然后 : 用 2 与它相乘 + + // 就和在数学里一样 + + perimeter = 2 * (width + height) + + fmt.Println(perimeter) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/\347\273\203\344\271\240/05-multi-assign/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/\347\273\203\344\271\240/05-multi-assign/main.go" new file mode 100644 index 000000000..dfe8dc2d1 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/\347\273\203\344\271\240/05-multi-assign/main.go" @@ -0,0 +1,36 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import "fmt" + +// --------------------------------------------------------- +// 练习: 多重赋值 +// +// 1. 使用多重赋值语句把 "go" 赋值到变量 `lang` 上 +// 以及 2 到变量 `version` 上 +// 2. 打印这些变量 +// +// 期望输出 +// go version 2 +// --------------------------------------------------------- + +func main() { + // 别动这些 + var ( + lang string + version int + ) + + // 在下面写上你的代码: + + // 别碰这个 + fmt.Println(lang, "version", version) + +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/\347\273\203\344\271\240/05-multi-assign/solution/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/\347\273\203\344\271\240/05-multi-assign/solution/main.go" new file mode 100644 index 000000000..14a8376c2 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/\347\273\203\344\271\240/05-multi-assign/solution/main.go" @@ -0,0 +1,22 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import "fmt" + +func main() { + var ( + lang string + version int + ) + + lang, version = "go", 2 + + fmt.Println(lang, "version", version) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/\347\273\203\344\271\240/06-multi-assign-2/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/\347\273\203\344\271\240/06-multi-assign-2/main.go" new file mode 100644 index 000000000..3c8883a84 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/\347\273\203\344\271\240/06-multi-assign-2/main.go" @@ -0,0 +1,38 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +// --------------------------------------------------------- +// 练习: 多重赋值 #2 +// +// 1. 将正确的值赋给各变量以和下面的 期望输出 相匹配 +// +// 2. 打印这些变量 +// +// 提示 +// 使用多个 Println 调用来打印每个句子 +// +// 期望输出 +// Air is good on Mars +// It's true +// It is 19.5 degrees +// --------------------------------------------------------- + +func main() { + // 去掉下面代码的注释 + + // var ( + // planet string + // isTrue bool + // temp float64 + // ) + + // 在下面写上你的代码 + +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/\347\273\203\344\271\240/06-multi-assign-2/solution/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/\347\273\203\344\271\240/06-multi-assign-2/solution/main.go" new file mode 100644 index 000000000..5b0d2331b --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/\347\273\203\344\271\240/06-multi-assign-2/solution/main.go" @@ -0,0 +1,25 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import "fmt" + +func main() { + var ( + planet string + isTrue bool + temp float64 + ) + + planet, isTrue, temp = "Mars", true, 19.5 + + fmt.Println("Air is good on", planet) + fmt.Println("It's", isTrue) + fmt.Println("It is", temp, "degrees") +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/\347\273\203\344\271\240/07-multi-short-func/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/\347\273\203\344\271\240/07-multi-short-func/main.go" new file mode 100644 index 000000000..ffc3e2f09 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/\347\273\203\344\271\240/07-multi-short-func/main.go" @@ -0,0 +1,42 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +// --------------------------------------------------------- +// 练习: 多重简短函数 +// +// 1. 使用多重简短声明语法声明两个变量 +// +// 2. 使用下方的 `multi` 函数初始化变量 +// +// 3. 在声明中丢弃第一个变量 +// +// 4. 只打印第二个变量 +// +// 注意 +// 你应该在初始化时使用 `multi` 函数 +// +// 期望输出 +// 4 +// --------------------------------------------------------- + +func main() { + // 在这添加你的声明 + // + + // 然后删掉下面代码的注释 + + // fmt.Println(b) + +} + +// multi 是一个返回多个 int 值的函数 +func multi() (int, int) { + return 5, 4 +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/\347\273\203\344\271\240/07-multi-short-func/solution/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/\347\273\203\344\271\240/07-multi-short-func/solution/main.go" new file mode 100644 index 000000000..99546e4a6 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/\347\273\203\344\271\240/07-multi-short-func/solution/main.go" @@ -0,0 +1,23 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import ( + "fmt" +) + +func main() { + _, b := multi() + + fmt.Println(b) +} + +func multi() (int, int) { + return 5, 4 +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/\347\273\203\344\271\240/08-swapper/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/\347\273\203\344\271\240/08-swapper/main.go" new file mode 100644 index 000000000..bb6256543 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/\347\273\203\344\271\240/08-swapper/main.go" @@ -0,0 +1,29 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +// --------------------------------------------------------- +// 练习: 交换器 +// +// 1. 同时将`color`改为 "orange", `color2` 改为 "绿色"。 +// (使用多重赋值) +// +// 2. 打印这些变量 +// +// 期望输出 +// orange green +// --------------------------------------------------------- + +func main() { + // 去掉下面代码的注释 + + // color, color2 := "red", "blue" + + // ? +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/\347\273\203\344\271\240/08-swapper/solution/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/\347\273\203\344\271\240/08-swapper/solution/main.go" new file mode 100644 index 000000000..2bb3937a7 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/\347\273\203\344\271\240/08-swapper/solution/main.go" @@ -0,0 +1,19 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import "fmt" + +func main() { + color, color2 := "red", "blue" + + color, color2 = "orange", "green" + + fmt.Println(color, color2) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/\347\273\203\344\271\240/09-swapper-2/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/\347\273\203\344\271\240/09-swapper-2/main.go" new file mode 100644 index 000000000..bb2b81236 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/\347\273\203\344\271\240/09-swapper-2/main.go" @@ -0,0 +1,28 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +// --------------------------------------------------------- +// 练习: 交换器 #2 +// +// 1. 交换 `red` 和 `blue` 这两个变量的值 +// +// 2. 打印它们 +// +// 期望输出 +// blue red +// --------------------------------------------------------- + +func main() { + // 去掉下面代码的注释: + + // red, blue := "red", "blue" + // ? + +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/\347\273\203\344\271\240/09-swapper-2/solution/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/\347\273\203\344\271\240/09-swapper-2/solution/main.go" new file mode 100644 index 000000000..b2aa86545 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/\347\273\203\344\271\240/09-swapper-2/solution/main.go" @@ -0,0 +1,19 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import "fmt" + +func main() { + red, blue := "red", "blue" + + red, blue = blue, red + + fmt.Println(red, blue) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/\347\273\203\344\271\240/10-discard-the-file/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/\347\273\203\344\271\240/10-discard-the-file/main.go" new file mode 100644 index 000000000..2f302960a --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/\347\273\203\344\271\240/10-discard-the-file/main.go" @@ -0,0 +1,30 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +// --------------------------------------------------------- +// 练习: 丢弃文件 +// +// 1. 使用 `path.Split`, 只打印 directory +// +// 2. 丢弃它 file 的部分 +// +// 限制 +// 使用简短声明 +// +// 期望输出 +// secret/ +// --------------------------------------------------------- + +func main() { + // 去掉下面代码的注释: + + // ? ?= path.Split("secret/file.txt") + +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/\347\273\203\344\271\240/10-discard-the-file/solution/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/\347\273\203\344\271\240/10-discard-the-file/solution/main.go" new file mode 100644 index 000000000..92925885f --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/\347\273\203\344\271\240/10-discard-the-file/solution/main.go" @@ -0,0 +1,20 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import ( + "fmt" + "path" +) + +func main() { + dir, _ := path.Split("secret/file.txt") + + fmt.Println(dir) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/\347\273\203\344\271\240/README.md" "b/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/\347\273\203\344\271\240/README.md" new file mode 100644 index 000000000..e42687780 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/\347\273\203\344\271\240/README.md" @@ -0,0 +1,26 @@ +# 赋值 + +赋值意味着 "复制" 值。在 Go 中, 所有东西都被复制了。之后你会了解更多这方面的信息。 + +现在, 脚踏实地尝试一些赋值练习 + +1. **[让他变蓝](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/04-赋值/练习/01-make-it-blue)** + +2. **[变量到变量](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/04-赋值/练习/02-vars-to-vars)** + +3. **[用表达式赋值](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/04-赋值/练习/03-assign-with-expressions)** + +4. **[找到矩形的周长](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/04-赋值/练习/04-find-the-rectangle-perimeter)** + +5. **[多重赋值](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/04-赋值/练习/05-multi-assign)** + +6. **[多重赋值 #2](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/04-赋值/练习/06-multi-assign-2)** + +7. **[多重简短函数](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/04-赋值/练习/07-multi-short-func)** + +8. **[交换器](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/04-赋值/练习/08-swapper)** + +9. **[交换器 #2](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/04-赋值/练习/09-swapper-2)** + +10. **[丢弃文件](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/04-赋值/练习/10-discard-the-file)** + diff --git "a/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/\351\227\256\351\242\230/README.md" "b/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/\351\227\256\351\242\230/README.md" new file mode 100644 index 000000000..fa7267a52 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/04-\350\265\213\345\200\274/\351\227\256\351\242\230/README.md" @@ -0,0 +1,81 @@ +## 当你把一个变量赋值给另一个变量时会发生什么? + +* 变量们变成同一个 +* 被赋值的变量被删除 +* 变量的值被改变为赋值变量的值 *正确* + +## 哪个是正确的赋值语句? + +```go +opened := true +``` + +* `closed := true` +* `opened = false` *正确* +* `var x = 2` + +## 哪个是正确的赋值语句? + +* `a, b = 3; 5` +* `c, d = true, false` *正确* +* `a, b, c = 5, 3` + +## 哪个是正确的赋值语句? + +```go +var ( + n = 3 + m int +) +``` + +* `m = "4"` +* `n = 10` *正确* +* `n = true` +* `m = false` + +## 哪个是正确的赋值语句? + +```go +var ( + n = 3 + m int + f float64 +) + +// one of the assignments below will be here + +fmt.Println(n, m, f) +``` + +* `n, m = 4, f` +* `n = false` +* `n, m, f = m + n, n + 5, 0.5` *正确* +* `n, m = 3.82, "hi"` + +## 哪个是正确的赋值语句? + +```go +var ( + a int + c bool +) +``` + +* `a = _` +* `c, _ = _, false` +* `_, _ = a, c` *正确* + +## 哪个是正确的赋值语句? + +**记住:** `path.Split` 返回两个 `string` 值 + +```go + var c, f string +``` + +* `_ = path.Split("assets/profile.png")` +* `_, _, c = path.Split("assets/profile.png")` +* `f = path.Split("assets/profile.png")` +* `_, f = path.Split("assets/profile.png")` *正确* + diff --git "a/translation/chinese/06-\345\217\230\351\207\217/05-\347\261\273\345\236\213\350\275\254\346\215\242/01-\347\240\264\345\235\217\346\200\247\347\232\204/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/05-\347\261\273\345\236\213\350\275\254\346\215\242/01-\347\240\264\345\235\217\346\200\247\347\232\204/main.go" new file mode 100644 index 000000000..597090d2a --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/05-\347\261\273\345\236\213\350\275\254\346\215\242/01-\347\240\264\345\235\217\346\200\247\347\232\204/main.go" @@ -0,0 +1,27 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import "fmt" + +func main() { + speed := 100 // int + force := 2.5 // float64 + + // 错误: 无效的操作符 + // ERROR: invalid op + // speed = speed * force + + // 转换可以是一个破坏性的操作 + // `force` 失去了它的分数部分... + + speed = speed * int(force) + + fmt.Println(speed) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/05-\347\261\273\345\236\213\350\275\254\346\215\242/02-\346\255\243\347\241\256\347\232\204/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/05-\347\261\273\345\236\213\350\275\254\346\215\242/02-\346\255\243\347\241\256\347\232\204/main.go" new file mode 100644 index 000000000..3374e965f --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/05-\347\261\273\345\236\213\350\275\254\346\215\242/02-\346\255\243\347\241\256\347\232\204/main.go" @@ -0,0 +1,32 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import "fmt" + +// 转化的顺序很重要... + +func main() { + speed := 100 + force := 2.5 + + fmt.Printf("speed : %T\n", speed) + fmt.Printf("conversion: %T\n", float64(speed)) + fmt.Printf("expression: %T\n", float64(speed)*force) + + // 类型不匹配: + // speed 是 int + // expression 是 float64 + // speed = float64(speed) * force + + // 正确: int * int + speed = int(float64(speed) * force) + + fmt.Println(speed) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/05-\347\261\273\345\236\213\350\275\254\346\215\242/03-\346\225\260\345\236\213\350\275\254\346\215\242/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/05-\347\261\273\345\236\213\350\275\254\346\215\242/03-\346\225\260\345\236\213\350\275\254\346\215\242/main.go" new file mode 100644 index 000000000..06315cafa --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/05-\347\261\273\345\236\213\350\275\254\346\215\242/03-\346\225\260\345\236\213\350\275\254\346\215\242/main.go" @@ -0,0 +1,48 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import "fmt" + +func main() { + var apple int + var orange int32 + + // 错误: + // 不能将 orange 赋值到 apple 上 (不同的类型) + // ERROR: + // cannot assign orange to apple (different types) + // apple = orange + + // 你需要将 orange 转换为 apple + + // orange 能够被转换为 int , + // 因为 int 和 int32 都是数字类型 + + apple = int(orange) + + // 你不能将一个数字类型转换为布尔类型 + // isDelicious := bool(orange) + + // 但是你可以将 int 转换为 string + // 这只对 int 类型生效 + orange = 65 // 65 is A + color := string(orange) + fmt.Println(color) + + // 这不能运行。 65.0 是 float. + // fmt.Println(string(65.0)) + + // 这能运行: 这有两个 byte 值 + // byte 也是 int + fmt.Println(string([]byte{104, 105})) + + _ = apple + +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/05-\347\261\273\345\236\213\350\275\254\346\215\242/\347\273\203\344\271\240/01-convert-and-fix/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/05-\347\261\273\345\236\213\350\275\254\346\215\242/\347\273\203\344\271\240/01-convert-and-fix/main.go" new file mode 100644 index 000000000..b45f66782 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/05-\347\261\273\345\236\213\350\275\254\346\215\242/\347\273\203\344\271\240/01-convert-and-fix/main.go" @@ -0,0 +1,23 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +// --------------------------------------------------------- +// 练习: 转换并修复 +// +// 使用类型转换表达式修复这些代码. +// +// 期望输出 +// 15.5 +// --------------------------------------------------------- + +func main() { + // a, b := 10, 5.5 + // fmt.Println(a + b) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/05-\347\261\273\345\236\213\350\275\254\346\215\242/\347\273\203\344\271\240/01-convert-and-fix/solution/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/05-\347\261\273\345\236\213\350\275\254\346\215\242/\347\273\203\344\271\240/01-convert-and-fix/solution/main.go" new file mode 100644 index 000000000..a72e16601 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/05-\347\261\273\345\236\213\350\275\254\346\215\242/\347\273\203\344\271\240/01-convert-and-fix/solution/main.go" @@ -0,0 +1,16 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import "fmt" + +func main() { + a, b := 10, 5.5 + fmt.Println(float64(a) + b) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/05-\347\261\273\345\236\213\350\275\254\346\215\242/\347\273\203\344\271\240/02-convert-and-fix-2/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/05-\347\261\273\345\236\213\350\275\254\346\215\242/\347\273\203\344\271\240/02-convert-and-fix-2/main.go" new file mode 100644 index 000000000..98685fbeb --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/05-\347\261\273\345\236\213\350\275\254\346\215\242/\347\273\203\344\271\240/02-convert-and-fix-2/main.go" @@ -0,0 +1,24 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +// --------------------------------------------------------- +// 练习: 转换并修复 #2 +// +// 使用类型转换表达式修复这些代码. +// +// 期望输出 +// 10.5 +// --------------------------------------------------------- + +func main() { + // a, b := 10, 5.5 + // a = b + // fmt.Println(a + b) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/05-\347\261\273\345\236\213\350\275\254\346\215\242/\347\273\203\344\271\240/02-convert-and-fix-2/solution/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/05-\347\261\273\345\236\213\350\275\254\346\215\242/\347\273\203\344\271\240/02-convert-and-fix-2/solution/main.go" new file mode 100644 index 000000000..31f1609cf --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/05-\347\261\273\345\236\213\350\275\254\346\215\242/\347\273\203\344\271\240/02-convert-and-fix-2/solution/main.go" @@ -0,0 +1,17 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import "fmt" + +func main() { + a, b := 10, 5.5 + a = int(b) + fmt.Println(float64(a) + b) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/05-\347\261\273\345\236\213\350\275\254\346\215\242/\347\273\203\344\271\240/03-convert-and-fix-3/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/05-\347\261\273\345\236\213\350\275\254\346\215\242/\347\273\203\344\271\240/03-convert-and-fix-3/main.go" new file mode 100644 index 000000000..b443afdb4 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/05-\347\261\273\345\236\213\350\275\254\346\215\242/\347\273\203\344\271\240/03-convert-and-fix-3/main.go" @@ -0,0 +1,22 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +// --------------------------------------------------------- +// 练习: 转换并修复 #3 +// +// 修复代码. +// +// 期望输出 +// 5.5 +// --------------------------------------------------------- + +func main() { + // fmt.Println(int(5.5)) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/05-\347\261\273\345\236\213\350\275\254\346\215\242/\347\273\203\344\271\240/03-convert-and-fix-3/solution/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/05-\347\261\273\345\236\213\350\275\254\346\215\242/\347\273\203\344\271\240/03-convert-and-fix-3/solution/main.go" new file mode 100644 index 000000000..0b751ed59 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/05-\347\261\273\345\236\213\350\275\254\346\215\242/\347\273\203\344\271\240/03-convert-and-fix-3/solution/main.go" @@ -0,0 +1,15 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import "fmt" + +func main() { + fmt.Println(5.5) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/05-\347\261\273\345\236\213\350\275\254\346\215\242/\347\273\203\344\271\240/04-convert-and-fix-4/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/05-\347\261\273\345\236\213\350\275\254\346\215\242/\347\273\203\344\271\240/04-convert-and-fix-4/main.go" new file mode 100644 index 000000000..1cc29dba5 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/05-\347\261\273\345\236\213\350\275\254\346\215\242/\347\273\203\344\271\240/04-convert-and-fix-4/main.go" @@ -0,0 +1,23 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +// --------------------------------------------------------- +// 练习: 转换并修复 #4 +// +// 修复代码. +// +// 期望输出 +// 9.5 +// --------------------------------------------------------- + +func main() { + // age := 2 + // fmt.Println(int(7.5) + int(age)) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/05-\347\261\273\345\236\213\350\275\254\346\215\242/\347\273\203\344\271\240/04-convert-and-fix-4/solution/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/05-\347\261\273\345\236\213\350\275\254\346\215\242/\347\273\203\344\271\240/04-convert-and-fix-4/solution/main.go" new file mode 100644 index 000000000..8c0a2dbef --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/05-\347\261\273\345\236\213\350\275\254\346\215\242/\347\273\203\344\271\240/04-convert-and-fix-4/solution/main.go" @@ -0,0 +1,16 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import "fmt" + +func main() { + age := 2 + fmt.Println(7.5 + float64(age)) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/05-\347\261\273\345\236\213\350\275\254\346\215\242/\347\273\203\344\271\240/05-convert-and-fix-5/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/05-\347\261\273\345\236\213\350\275\254\346\215\242/\347\273\203\344\271\240/05-convert-and-fix-5/main.go" new file mode 100644 index 000000000..23317d5c8 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/05-\347\261\273\345\236\213\350\275\254\346\215\242/\347\273\203\344\271\240/05-convert-and-fix-5/main.go" @@ -0,0 +1,33 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import "fmt" + +// --------------------------------------------------------- +// 练习: 转换并修复 #5 +// +// 修复代码. +// +// 提示 +// int8 的最大值是 127 +// int16 的最大值是 32767 +// +// 期望输出 +// 1127 +// --------------------------------------------------------- + +func main() { + // 不要修改这些变量 + min := int8(127) + max := int16(1000) + + // 修复代码 + fmt.Println(int8(max) + min) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/05-\347\261\273\345\236\213\350\275\254\346\215\242/\347\273\203\344\271\240/05-convert-and-fix-5/solution/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/05-\347\261\273\345\236\213\350\275\254\346\215\242/\347\273\203\344\271\240/05-convert-and-fix-5/solution/main.go" new file mode 100644 index 000000000..a2b147ef5 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/05-\347\261\273\345\236\213\350\275\254\346\215\242/\347\273\203\344\271\240/05-convert-and-fix-5/solution/main.go" @@ -0,0 +1,31 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import "fmt" + +func main() { + min := int8(127) + max := int16(1000) + + fmt.Println(max + int16(min)) + + // 解释 + // + // `int8(max)` 损失了 max 的信息 + // 导致它减小到了 127 + // 也就是 int8 的最大值 + // + // 正确的转换时 int16(min) + // 因为 int16 > int8 + // 当你这样做时, min 不会损失信息 + // + // 你会在 "Go 类型系统" 这节学到更多 + +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/05-\347\261\273\345\236\213\350\275\254\346\215\242/\347\273\203\344\271\240/README.md" "b/translation/chinese/06-\345\217\230\351\207\217/05-\347\261\273\345\236\213\350\275\254\346\215\242/\347\273\203\344\271\240/README.md" new file mode 100644 index 000000000..233ccd40f --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/05-\347\261\273\345\236\213\350\275\254\346\215\242/\347\273\203\344\271\240/README.md" @@ -0,0 +1,14 @@ +# 类型转换 + +这里为你准备了 5 个练习。你必须找到这些错误,然后用正确的类型转换来修复它们。 + +1. **[Convert and Fix #1](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/05-类型转换/练习/01-convert-and-fix)** + +2. **[Convert and Fix #2](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/05-类型转换/练习/02-convert-and-fix-2)** + +3. **[Convert and Fix #3](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/05-类型转换/练习/03-convert-and-fix-3)** + +4. **[Convert and Fix #4](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/05-类型转换/练习/04-convert-and-fix-4)** + +5. **[Convert and Fix #5](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/05-类型转换/练习/05-convert-and-fix-5)** + diff --git "a/translation/chinese/06-\345\217\230\351\207\217/05-\347\261\273\345\236\213\350\275\254\346\215\242/\351\227\256\351\242\230/questions.md" "b/translation/chinese/06-\345\217\230\351\207\217/05-\347\261\273\345\236\213\350\275\254\346\215\242/\351\227\256\351\242\230/questions.md" new file mode 100644 index 000000000..039941515 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/05-\347\261\273\345\236\213\350\275\254\346\215\242/\351\227\256\351\242\230/questions.md" @@ -0,0 +1,75 @@ +## 哪一个是正确的类型转换表达式? + +* convert(40) +* var("hi") +* int(4.) *正确* +* int[4] + +## 这段代码打印什么? + +```go +age := 6.5 +fmt.Print(int(age)) +``` + +* 6.5 +* 65 +* 6 *正确* +* .5 + +> 当你把一个 float 转换为 int 时 +> 它失去了它的小数部分 + +## 这段代码打印什么? + +```go +fmt.Print(int(6.5)) +``` + +* 6.5 +* 65 +* 6 +* Compile-Time Error *正确* + +> Go可以在编译时检测转换错误 + +## 这段代码打印什么? + +```go +area := 10.5 +fmt.Print(area/2) +``` + +* 5.25 *正确* +* 5 +* 0 +* Error + +## 这段代码打印什么? + +```go +area := 10.5 +div := 2 +fmt.Print(area/div) +``` + +* 5.25 +* 5 +* ERROR *正确* + +> 你不能除以不同类型的值 +> 你需要转换:`area / float64(div)` + +## 下面哪段代码能修复这段代码? + +```go +area := 10.5 +div := 2 +fmt.Print(area/div) +``` + +* `fmt.Print(int(area)/div)` // 5 +* `fmt.Print(area/int(div))` // 类型不匹配 +* `fmt.Print(int(area)/int(div))` // 5 +* `fmt.Print(area/float64(div))` *正确* + diff --git "a/translation/chinese/06-\345\217\230\351\207\217/06-\351\227\256\345\200\231\345\221\230\351\241\271\347\233\256/01-\346\274\224\347\244\272/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/06-\351\227\256\345\200\231\345\221\230\351\241\271\347\233\256/01-\346\274\224\347\244\272/main.go" new file mode 100644 index 000000000..2f978c346 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/06-\351\227\256\345\200\231\345\221\230\351\241\271\347\233\256/01-\346\274\224\347\244\272/main.go" @@ -0,0 +1,32 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import ( + "fmt" + "os" +) + +// 注意: 至少要用3个参数来运行这个程序 +// 否则它会报错 + +func main() { + fmt.Printf("%#v\n", os.Args) + + // 从 os.Args 字符串切片中获取一个 item + // os.Args[INDEX] + // INDEX 可以是 0 或者更大 + fmt.Println("Path:", os.Args[0]) + fmt.Println("1st argument:", os.Args[1]) + fmt.Println("2nd argument:", os.Args[2]) + fmt.Println("3rd argument:", os.Args[3]) + + // `len` 可以知道有多少个 item 在切片值中 + fmt.Println("Items inside os.Args:", len(os.Args)) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/06-\351\227\256\345\200\231\345\221\230\351\241\271\347\233\256/02-\347\211\210\346\234\2541/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/06-\351\227\256\345\200\231\345\221\230\351\241\271\347\233\256/02-\347\211\210\346\234\2541/main.go" new file mode 100644 index 000000000..24eba55e1 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/06-\351\227\256\345\200\231\345\221\230\351\241\271\347\233\256/02-\347\211\210\346\234\2541/main.go" @@ -0,0 +1,36 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import ( + "fmt" + "os" +) + +// 因为, 还没有学到关于控制流语句的知识 +// 在这里没有包含错误检测 +// +// 所以, 如果你没有传递 name, +// 程序会出错, +// 这是有意为之的 + +func main() { + var name string + + // 给下面的字符串变量赋一个新值 + name = os.Args[1] + fmt.Println("Hello great", name, "!") + + // 修改 name, 声明 age 并赋值 85 + name, age := "gandalf", 85 + + fmt.Println("My name is", name) + fmt.Println("My age is", age) + fmt.Println("BTW, you shall pass!") +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/06-\351\227\256\345\200\231\345\221\230\351\241\271\347\233\256/03-\347\211\210\346\234\2542/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/06-\351\227\256\345\200\231\345\221\230\351\241\271\347\233\256/03-\347\211\210\346\234\2542/main.go" new file mode 100644 index 000000000..4819f6ae7 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/06-\351\227\256\345\200\231\345\221\230\351\241\271\347\233\256/03-\347\211\210\346\234\2542/main.go" @@ -0,0 +1,34 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import ( + "fmt" + "os" +) + +// 因为, 还没有学到关于控制流语句的知识 +// 在这里没有包含错误检测 +// +// 所以, 如果你没有传递 name, +// 程序会出错, +// 这是有意为之的 + +func main() { + // 给下面的字符串变量赋一个新值 + name := os.Args[1] + fmt.Println("Hello great", name, "!") + + // 修改 name, 声明 age 并赋值 85 + name, age := "gandalf", 85 + + fmt.Println("My name is", name) + fmt.Println("My age is", age) + fmt.Println("BTW, you shall pass!") +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/06-\351\227\256\345\200\231\345\221\230\351\241\271\347\233\256/\347\273\203\344\271\240/01-count-arguments/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/06-\351\227\256\345\200\231\345\221\230\351\241\271\347\233\256/\347\273\203\344\271\240/01-count-arguments/main.go" new file mode 100644 index 000000000..f09a5ef0f --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/06-\351\227\256\345\200\231\345\221\230\351\241\271\347\233\256/\347\273\203\344\271\240/01-count-arguments/main.go" @@ -0,0 +1,29 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +// --------------------------------------------------------- +// 练习: 数参数 +// +// 打印命令行参数的个数 +// +// 输入 +// bilbo balbo bungo +// +// 期望输出 +// There are 3 names. +// --------------------------------------------------------- + +func main() { + // 去掉注释 & 修复代码 + // count := ? + + // 去掉注释 & 然后别动他 + // fmt.Printf("There are %d names.\n", count) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/06-\351\227\256\345\200\231\345\221\230\351\241\271\347\233\256/\347\273\203\344\271\240/01-count-arguments/solution/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/06-\351\227\256\345\200\231\345\221\230\351\241\271\347\233\256/\347\273\203\344\271\240/01-count-arguments/solution/main.go" new file mode 100644 index 000000000..86d4b79b5 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/06-\351\227\256\345\200\231\345\221\230\351\241\271\347\233\256/\347\273\203\344\271\240/01-count-arguments/solution/main.go" @@ -0,0 +1,20 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import ( + "fmt" + "os" +) + +func main() { + count := len(os.Args) - 1 + + fmt.Printf("There are %d names.\n", count) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/06-\351\227\256\345\200\231\345\221\230\351\241\271\347\233\256/\347\273\203\344\271\240/02-print-the-path/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/06-\351\227\256\345\200\231\345\221\230\351\241\271\347\233\256/\347\273\203\344\271\240/02-print-the-path/main.go" new file mode 100644 index 000000000..45b7f687a --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/06-\351\227\256\345\200\231\345\221\230\351\241\271\347\233\256/\347\273\203\344\271\240/02-print-the-path/main.go" @@ -0,0 +1,25 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +// --------------------------------------------------------- +// 练习: 打印路径 +// +// 从变量 `os.Args` 中获取运行程序的路径并打印它 +// +// 提示 +// 用 `go build` 来构建你的程序 +// 然后通过编译后的可执行程序运行它 +// +// 预期输出应包含 +// myprogram +// --------------------------------------------------------- + +func main() { +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/06-\351\227\256\345\200\231\345\221\230\351\241\271\347\233\256/\347\273\203\344\271\240/02-print-the-path/solution/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/06-\351\227\256\345\200\231\345\221\230\351\241\271\347\233\256/\347\273\203\344\271\240/02-print-the-path/solution/main.go" new file mode 100644 index 000000000..1a966614f --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/06-\351\227\256\345\200\231\345\221\230\351\241\271\347\233\256/\347\273\203\344\271\240/02-print-the-path/solution/main.go" @@ -0,0 +1,29 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import ( + "fmt" + "os" +) + +// 步骤: +// +// 输入下面的命令来编译: +// go build -o myprogram +// +// 然后输入下面的命令来运行: +// ./myprogram +// +// 如果是 Windows, 输入: +// myprogram + +func main() { + fmt.Println(os.Args[0]) +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/06-\351\227\256\345\200\231\345\221\230\351\241\271\347\233\256/\347\273\203\344\271\240/03-print-your-name/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/06-\351\227\256\345\200\231\345\221\230\351\241\271\347\233\256/\347\273\203\344\271\240/03-print-your-name/main.go" new file mode 100644 index 000000000..7e0d7fb77 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/06-\351\227\256\345\200\231\345\221\230\351\241\271\347\233\256/\347\273\203\344\271\240/03-print-your-name/main.go" @@ -0,0 +1,37 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +// --------------------------------------------------------- +// 练习: 打印你的名字 +// +// 从第一个命令行参数来获取名字 +// +// 输入 +// 用你的名字来运行这个程序 (指传入你的名字作为参数) +// +// 期望输出 +// 你的名字 +// +// 例子 +// go run main.go inanc +// +// inanc +// +// 附加题: 让输出变成下面这样: +// +// go run main.go inanc +// Hi inanc +// How are you? +// --------------------------------------------------------- + +func main() { + // 从第一个命令行参数来获取名字 + // 打印它 +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/06-\351\227\256\345\200\231\345\221\230\351\241\271\347\233\256/\347\273\203\344\271\240/03-print-your-name/solution/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/06-\351\227\256\345\200\231\345\221\230\351\241\271\347\233\256/\347\273\203\344\271\240/03-print-your-name/solution/main.go" new file mode 100644 index 000000000..6135199be --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/06-\351\227\256\345\200\231\345\221\230\351\241\271\347\233\256/\347\273\203\344\271\240/03-print-your-name/solution/main.go" @@ -0,0 +1,22 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import ( + "fmt" + "os" +) + +func main() { + fmt.Println(os.Args[1]) + + // 附加题答案 + fmt.Println("Hello", os.Args[1]) + fmt.Println("How are you?") +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/06-\351\227\256\345\200\231\345\221\230\351\241\271\347\233\256/\347\273\203\344\271\240/04-greet-more-people/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/06-\351\227\256\345\200\231\345\221\230\351\241\271\347\233\256/\347\273\203\344\271\240/04-greet-more-people/main.go" new file mode 100644 index 000000000..4579e4ede --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/06-\351\227\256\345\200\231\345\221\230\351\241\271\347\233\256/\347\273\203\344\271\240/04-greet-more-people/main.go" @@ -0,0 +1,37 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +// --------------------------------------------------------- +// 练习: 问候更多人 +// +// 限制 +// 1. 请确保与下面的预期输出相匹配 +// 2. 将参数的长度存储在一个变量中 +// 3. 将所有参数也存储在变量中 +// +// 输入 +// bilbo balbo bungo +// +// 期望输出 +// There are 3 people! +// Hello great bilbo ! +// Hello great balbo ! +// Hello great bungo ! +// Nice to meet you all. +// --------------------------------------------------------- + +func main() { + // 在这写你的代码 + + // 附加题 #1: + // 传递少于3个参数, 然后观察错误。 + // 在网上搜索如何解决这个问题 + +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/06-\351\227\256\345\200\231\345\221\230\351\241\271\347\233\256/\347\273\203\344\271\240/04-greet-more-people/solution/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/06-\351\227\256\345\200\231\345\221\230\351\241\271\347\233\256/\347\273\203\344\271\240/04-greet-more-people/solution/main.go" new file mode 100644 index 000000000..275cacd3a --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/06-\351\227\256\345\200\231\345\221\230\351\241\271\347\233\256/\347\273\203\344\271\240/04-greet-more-people/solution/main.go" @@ -0,0 +1,29 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import ( + "fmt" + "os" +) + +func main() { + var ( + l = len(os.Args) - 1 + n1 = os.Args[1] + n2 = os.Args[2] + n3 = os.Args[3] + ) + + fmt.Println("There are", l, "people !") + fmt.Println("Hello great", n1, "!") + fmt.Println("Hello great", n2, "!") + fmt.Println("Hello great", n3, "!") + fmt.Println("Nice to meet you all.") +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/06-\351\227\256\345\200\231\345\221\230\351\241\271\347\233\256/\347\273\203\344\271\240/05-greet-5-people/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/06-\351\227\256\345\200\231\345\221\230\351\241\271\347\233\256/\347\273\203\344\271\240/05-greet-5-people/main.go" new file mode 100644 index 000000000..7988fbdd5 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/06-\351\227\256\345\200\231\345\221\230\351\241\271\347\233\256/\347\273\203\344\271\240/05-greet-5-people/main.go" @@ -0,0 +1,36 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +// --------------------------------------------------------- +// 练习: 问候 5 个人 +// +// 这次问候 5 个人 +// +// 不要从上一个练习中复制粘贴代码 +// +// 限制 +// 这次不要用变量 +// +// 输入 +// bilbo balbo bungo gandalf legolas +// +// 期望输出 +// There are 5 people! +// Hello great bilbo ! +// Hello great balbo ! +// Hello great bungo ! +// Hello great gandalf ! +// Hello great legolas ! +// Nice to meet you all. +// --------------------------------------------------------- + +func main() { + // 在这写你的代码 +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/06-\351\227\256\345\200\231\345\221\230\351\241\271\347\233\256/\347\273\203\344\271\240/05-greet-5-people/solution/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/06-\351\227\256\345\200\231\345\221\230\351\241\271\347\233\256/\347\273\203\344\271\240/05-greet-5-people/solution/main.go" new file mode 100644 index 000000000..688fe0d53 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/06-\351\227\256\345\200\231\345\221\230\351\241\271\347\233\256/\347\273\203\344\271\240/05-greet-5-people/solution/main.go" @@ -0,0 +1,24 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import ( + "fmt" + "os" +) + +func main() { + fmt.Println("There are", len(os.Args)-1, "people !") + fmt.Println("Hello great", os.Args[1], "!") + fmt.Println("Hello great", os.Args[2], "!") + fmt.Println("Hello great", os.Args[3], "!") + fmt.Println("Hello great", os.Args[4], "!") + fmt.Println("Hello great", os.Args[5], "!") + fmt.Println("Nice to meet you all.") +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/06-\351\227\256\345\200\231\345\221\230\351\241\271\347\233\256/\347\273\203\344\271\240/README.md" "b/translation/chinese/06-\345\217\230\351\207\217/06-\351\227\256\345\200\231\345\221\230\351\241\271\347\233\256/\347\273\203\344\271\240/README.md" new file mode 100644 index 000000000..51a2d4407 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/06-\351\227\256\345\200\231\345\221\230\351\241\271\347\233\256/\347\273\203\344\271\240/README.md" @@ -0,0 +1,12 @@ +# 命令行参数 + +1. **[数参数](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/06-问候员项目/练习/01-count-arguments)** + +2. **[打印路径](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/06-问候员项目/练习/02-print-the-path)** + +3. **[打印你的名字](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/06-问候员项目/练习/03-print-your-name)** + +4. **[问候更多人](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/06-问候员项目/练习/04-greet-more-people)** + +5. **[问候 5 个人](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/06-问候员项目/练习/05-greet-5-people)** + diff --git "a/translation/chinese/06-\345\217\230\351\207\217/06-\351\227\256\345\200\231\345\221\230\351\241\271\347\233\256/\347\273\203\344\271\240/solution-to-the-lecture-exercise/main.go" "b/translation/chinese/06-\345\217\230\351\207\217/06-\351\227\256\345\200\231\345\221\230\351\241\271\347\233\256/\347\273\203\344\271\240/solution-to-the-lecture-exercise/main.go" new file mode 100644 index 000000000..bddb0844d --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/06-\351\227\256\345\200\231\345\221\230\351\241\271\347\233\256/\347\273\203\344\271\240/solution-to-the-lecture-exercise/main.go" @@ -0,0 +1,42 @@ +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// +// For more tutorials : https://learngoprogramming.com +// In-person training : https://www.linkedin.com/in/inancgumus/ +// Follow me on twitter: https://twitter.com/inancgumus + +package main + +import ( + "fmt" + "os" +) + +// --------------------------------------------------------- +// 这是我在讲座中提到的练习的答案 +// --------------------------------------------------------- + +// 注意: 你至少要用 3 个参数来运行这个程序 +// 否则它会报错 + +func main() { + // 给下面的字符串变量赋一个新值 + var ( + name = os.Args[1] + name2 = os.Args[2] + name3 = os.Args[3] + ) + + fmt.Println("Hello great", name, "!") + fmt.Println("And hellooo to you magnificient", name2, "!") + fmt.Println("Welcome", name3, "!") + + // 修改 name, 声明 age 变量并赋值 131 + name, age := "bilbo baggins", 131 // 未知年龄! + + fmt.Println("My name is", name) + fmt.Println("My age is", age) + fmt.Println("And, I love adventures!") + +} diff --git "a/translation/chinese/06-\345\217\230\351\207\217/06-\351\227\256\345\200\231\345\221\230\351\241\271\347\233\256/\351\227\256\351\242\230/questions.md" "b/translation/chinese/06-\345\217\230\351\207\217/06-\351\227\256\345\200\231\345\221\230\351\241\271\347\233\256/\351\227\256\351\242\230/questions.md" new file mode 100644 index 000000000..468284ee3 --- /dev/null +++ "b/translation/chinese/06-\345\217\230\351\207\217/06-\351\227\256\345\200\231\345\221\230\351\241\271\347\233\256/\351\227\256\351\242\230/questions.md" @@ -0,0 +1,66 @@ +## `os.Args` 变量在其第一项中存储了什么? + +* 传递给程序的第一个参数 +* 传递给程序的第二个参数 +* 运行程序的路径 *正确* + +## `Args` 变量的类型是什么? + +```go +var Args []string +``` + +* string +* string 数组 +* strings 的切片 *正确* + +## `Args` 变量中每个值的类型是什么? + +```go +var Args []string +``` + +* string *正确* +* string 数组 +* strings 的切片 + +## 如何获得 `Args` 变量的第一项? + +```go +var Args []string +``` + +* Args.0 +* Args{1} +* Args[0] *正确* +* Args(1) + +## 如何获得 `Args` 变量的第二项? + +```go +var Args []string +``` + +* Args.2 +* Args[1] *正确* +* Args{1} +* Args(2) + +## 如何获得 `Args` 变量的长度? + +```go +var Args []string +``` + +* length(Args) +* Args.len +* len(Args) *正确* +* Args.Length + +## 如何从命令行获得第一个 "argument"? + +* os.Args[0] +* os.Args[1] *正确* +* os.Args[2] +* os.Args[3] +