Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Golang #20

Open
zxy16305 opened this issue Jun 25, 2018 · 3 comments
Open

Golang #20

zxy16305 opened this issue Jun 25, 2018 · 3 comments
Labels

Comments

@zxy16305
Copy link
Owner

zxy16305 commented Jun 25, 2018

特性详见 官方教程 && 本文概要其特性 -> 相当于目录

@zxy16305
Copy link
Owner Author

zxy16305 commented Jun 25, 2018

Basics-1

与C申明语法的不同

  • Go申明从左到右, 如
var x int
var p *int
var a [3]int
  • Go申明可不写变量名,如
f func(func(int,int) int, int) func(int, int) int
  • 指针申明写法沿用C

挣扎了一下

func add(x, y int) int {
	return x + y
}
func swap(x, y string) (string, string) {
	return y, x
}

func main() {
	a, b := swap("hello", "world")
	fmt.Println(a, b)
}
func split(sum int) (x, y int) {
	x = sum * 4 / 9
	y = sum - x
	return 
        // return 1,2
}
var i, j int = 1, 2
var c, python, java = true, false, "no!"
var i, j int = 1, 2
k := 3
c, python, java := true, false, "no!"

其中多了复数complex64、complex128

	var f float64 = math.Sqrt(float64(16 + 9))
	var z uint = uint(f)

@zxy16305
Copy link
Owner Author

Basic-2

sum := 0
for i := 0; i < 10; i++ {
	sum += i
}
fmt.Println(sum)
  • if,条件不需要括号,执行体必须大括号;if中可以声明变量;
if x < 0 {
	return sqrt(-x) + "i"
}
if v := math.Pow(x, n); v < lim {
	return v
}
func main() {
	fmt.Println("counting")

	for i := 0; i < 10; i++ {
		defer fmt.Println(i)
	}

	fmt.Println("done")
}

相关介绍 Defer, Panic, and Recover

@zxy16305 zxy16305 added the Go label Jun 25, 2018
@zxy16305
Copy link
Owner Author

zxy16305 commented Jun 26, 2018

Basic-3

只记关键字了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant