Comments (3)
Basics-1
- 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等价
var i, j int = 1, 2
k := 3
c, python, java := true, false, "no!"
其中多了复数complex64、complex128
- 类型强转,使用T(v),另外Go没有类型提升
var f float64 = math.Sqrt(float64(16 + 9))
var z uint = uint(f)
from blog.
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
}
- else,if头声明的变量,else中有效
- switch,不需要break;case可接变量、以及非整形;switch后不接条件默认条件为true,代替if-else if-else....
- Defer,返回时执行,但其参数是立即传递的;多个defer后进先出(栈),
func main() {
fmt.Println("counting")
for i := 0; i < 10; i++ {
defer fmt.Println(i)
}
fmt.Println("done")
}
from blog.
Basic-3
只记关键字了
from blog.
Related Issues (20)
- spring源码阅读笔记 HOT 13
- spring源码阅读笔记④--RequestDispatcherServlet
- springboot笔记 HOT 6
- springcloud文档阅读笔记
- spring data JPA 笔记 HOT 3
- Blog 项目所遇到部分问题 HOT 1
- MYSQL笔记 HOT 2
- Intellij Idea相关笔记 HOT 3
- Javascript/TypeScript/thymeleaf.....
- Java-other HOT 2
- Tool Mark HOT 2
- spring源码阅读笔记②--常用接口
- spring源码阅读笔记③
- spring源码阅读笔记⑤--注解记录--持续更新
- maven笔记 HOT 1
- springboot配置服务器符合CORS规范
- 《鸟叔的Linux私房菜》读书笔记 HOT 1
- Spring Security 文档阅读笔记 HOT 1
- code-base HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from blog.