GithubHelp home page GithubHelp logo

Golang about blog HOT 3 OPEN

zxy16305 avatar zxy16305 commented on July 26, 2024
Golang

from blog.

Comments (3)

zxy16305 avatar zxy16305 commented on July 26, 2024

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)

from blog.

zxy16305 avatar zxy16305 commented on July 26, 2024

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

from blog.

zxy16305 avatar zxy16305 commented on July 26, 2024

Basic-3

只记关键字了

from blog.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.