6 Star 2 Fork 0

yao_yu / Golang_Study

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

#Golang学习 ##基础 ###包、变量和函数

`package` XXX
导入 `import` ("xxx")
导出名 首字母大写的名称是被导出的

函数

`func` xxx(x, y int)(c, d int){}
当两个或多个连续的函数命名参数是同一类型,则除了最后一个类型之外,其他都可以省略。
函数可以返回任意数量的返回值
返回值可以被命名,并且像变量那样使用

变量

`var` c, python, java bool
`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!"
函数外的每个语句都必须以关键字开始(`var`、`func`、等等),`:=` 结构不能使用在函数外。
- 基本类型
- 零值
	数值类型为 `0`,
	布尔类型为 `false`,
	字符串为 `""`(空字符串)。
- 类型转换
	`T`(v)
- 类型推导
- 常量
	`const`

###流程控制语句:for、if、else 和 switch ####for for i := 0; i < 10; i++ {} for i < 10 {} (<==> while) ####if if x < 0 {} if v := math.Pow(x, n); v < lim {} if else ####switch fallthrough 没有条件的switch <==> if-then-else ####defer 延迟执行,按栈方式后进先出执行

###复杂类型: struct, slice和map

The MIT License (MIT) Copyright (c) 2014 yao_yu Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

Go语言学习实例 展开 收起
Go
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Go
1
https://gitee.com/yao_yu/Golang_Study.git
git@gitee.com:yao_yu/Golang_Study.git
yao_yu
Golang_Study
Golang_Study
master

搜索帮助