-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add: 07 Chinese version
- Loading branch information
Showing
27 changed files
with
668 additions
and
0 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
translation/chinese/07-打印/01-介绍/01-println-vs-printf/main.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
|
||
func main() { | ||
ops, ok, fail := 2350, 543, 433 | ||
|
||
fmt.Println( | ||
"total:", ops, "- success:", ok, "/", fail, | ||
) | ||
|
||
fmt.Printf( | ||
"total: %d - success: %d / %d\n", | ||
ops, ok, fail, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() { | ||
var brand string | ||
|
||
// 像这样 "" 引用形式打印字符串 | ||
fmt.Printf("%q\n", brand) | ||
|
||
brand = "Google" | ||
fmt.Printf("%q\n", brand) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() { | ||
// 没有换行符 | ||
fmt.Println("hihi") | ||
|
||
// 使用换行符: | ||
// \n = 转义序列 | ||
// \ = 转义字符 | ||
fmt.Println("hi\nhi") | ||
|
||
// 转义字符: | ||
// \\ = \ | ||
// \" = " | ||
fmt.Println("hi\\n\"hi\"") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.Printf("%T\n", speed) | ||
fmt.Printf("%T\n", heat) | ||
fmt.Printf("%T\n", off) | ||
fmt.Printf("%T\n", brand) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// 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 = "venus" | ||
distance = 261 | ||
orbital = 224.701 | ||
hasLife = false | ||
) | ||
|
||
// 全能打印 %v 动词 | ||
fmt.Printf("Planet: %v\n", planet) | ||
fmt.Printf("Distance: %v millions kms\n", distance) | ||
fmt.Printf("Orbital Period: %v days\n", orbital) | ||
fmt.Printf("Does %v have life? %v\n", planet, hasLife) | ||
|
||
// 参数索引 - 索引从 1 开始 | ||
fmt.Printf( | ||
"%v is %v away. Think! %[2]v kms! %[1]v OMG.\n", | ||
planet, distance, | ||
) | ||
|
||
// 为什么不使用别的打印词? | ||
// 原因: 有可能因为类型不正确导致报错 | ||
// | ||
// fmt.Printf("Planet: %d\n", planet) | ||
// fmt.Printf("Distance: %s millions kms\n", distance) | ||
// fmt.Printf("Orbital Period: %t days\n", orbital) | ||
// fmt.Printf("Does %v has life? %f\n", planet, hasLife) | ||
|
||
// 正确的打印动词: | ||
// fmt.Printf("Planet: %s\n", planet) | ||
// fmt.Printf("Distance: %d millions kms\n", distance) | ||
// fmt.Printf("Orbital Period: %f days\n", orbital) | ||
// fmt.Printf("Does %s has life? %t\n", planet, hasLife) | ||
|
||
// 更加精确的打印动词 | ||
fmt.Printf("Orbital Period: %f days\n", orbital) | ||
fmt.Printf("Orbital Period: %.0f days\n", orbital) | ||
fmt.Printf("Orbital Period: %.1f days\n", orbital) | ||
fmt.Printf("Orbital Period: %.2f days\n", orbital) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
||
// --------------------------------------------------------- | ||
// 练习: 打印你的年来 | ||
// | ||
// 使用 Printf 打印你的年龄 | ||
// | ||
// 期望输出 | ||
// I'm 30 years old. | ||
// | ||
// 注意 | ||
// 你应该把你的年龄给程 30 岁 | ||
// --------------------------------------------------------- | ||
|
||
func main() { | ||
// ? | ||
} |
15 changes: 15 additions & 0 deletions
15
translation/chinese/07-打印/练习/01-print-your-age/solution/main.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.Printf("I'm %d years old.\n", 30) | ||
} |
28 changes: 28 additions & 0 deletions
28
translation/chinese/07-打印/练习/02-print-your-name-and-lastname/main.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
||
// --------------------------------------------------------- | ||
// 练习:打印您的名字和姓氏 | ||
// | ||
// 使用 Printf 您的名字和姓氏 | ||
// | ||
// 期望输出 | ||
// My name is Inanc and my lastname is Gumus. | ||
// | ||
// 额外 | ||
// 把打印格式声明字符串 (Printf 的第一个参数) 存到一个变量 | ||
// 然后传递到 Printf | ||
// --------------------------------------------------------- | ||
|
||
func main() { | ||
// 额外: 使用一个变量存打印格式声明字符串 | ||
|
||
// fmt.Printf("?", ?, ?) | ||
} |
19 changes: 19 additions & 0 deletions
19
translation/chinese/07-打印/练习/02-print-your-name-and-lastname/solution/main.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.Printf("My name is %s and my lastname is %s.\n", "Inanc", "Gumus") | ||
|
||
// 额外 | ||
msg := "My name is %s and my lastname is %s.\n" | ||
fmt.Printf(msg, "Inanc", "Gumus") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
||
// --------------------------------------------------------- | ||
// 练习: false 声明 | ||
// | ||
// 使用 Printf 使用变量打印预期输出 | ||
// | ||
// 期望输出 | ||
// These are false claims. | ||
// --------------------------------------------------------- | ||
|
||
func main() { | ||
// 将注释下的代码去掉注释 | ||
// 然后移到你的代码中 | ||
// tf := false | ||
|
||
// 将你的代码写到下面 | ||
// ? | ||
} |
16 changes: 16 additions & 0 deletions
16
translation/chinese/07-打印/练习/03-false-claims/solution/main.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() { | ||
tf := false | ||
fmt.Printf("These are %t claims.\n", tf) | ||
} |
26 changes: 26 additions & 0 deletions
26
translation/chinese/07-打印/练习/04-print-the-temperature/main.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
||
// --------------------------------------------------------- | ||
// 练习:打印温度 | ||
// | ||
// 使用 Printf 打印您所在地区的当前温度 | ||
// | ||
// 注意 | ||
// 不要使用 %v 动词 | ||
// 输出不应该是 29.500000 | ||
// | ||
// 期望输出 | ||
// Temperature is 29.5 degrees. | ||
// --------------------------------------------------------- | ||
|
||
func main() { | ||
// ? | ||
} |
15 changes: 15 additions & 0 deletions
15
translation/chinese/07-打印/练习/04-print-the-temperature/solution/main.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.Printf("Temperature is %.1f degrees.\n", 29.5) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
||
// --------------------------------------------------------- | ||
// 练习:双引号 | ||
// | ||
// 使用 Printf 打印带有双引号的 "hello world" | ||
//(正如你在这里看到的) | ||
// | ||
// 注意 | ||
// 输出不应该只是 hello world | ||
// | ||
// 期待输出 | ||
// "hello world" | ||
// --------------------------------------------------------- | ||
|
||
func main() { | ||
// ? | ||
} |
15 changes: 15 additions & 0 deletions
15
translation/chinese/07-打印/练习/05-double-quotes/solution/main.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.Printf("%q\n", "hello world") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
||
// --------------------------------------------------------- | ||
// 练习:打印字体 | ||
// | ||
// 使用 fmt.Printf 打印 3 的类型和值 | ||
// | ||
// 期望输出 | ||
// Type of 3 is int | ||
// --------------------------------------------------------- | ||
|
||
func main() { | ||
// ? | ||
} |
Oops, something went wrong.