golang初识3 - func
1. 功能块(function block)
格式:
func function_name( [parameter list] ) [return_types] {
//body
}
与delphi的异同:
(1)关键字
Delphi: procedure 和 function
Go: 使用一个func替代以上2个。
(2)参数列表
Delphi: 使用冒号(:)来声明
Go:省略冒号(:)
(3)返回值
Delphi:使用冒号(:)来声明,并且只能返回一个!
Go:省略冒号(:),而且能返回多个(牛X的一点)
src:termial_factorial.go
package main import (
"fmt"
"os"
"strconv"
) func main() {
input, err := strconv.Atoi(os.Args[])
if err != nil {
fmt.Println(err)
}
x, y := mul_add(input)
fmt.Println("阶加", input, "=" ,x, "\n阶乘,累加", input, "=", y)
} func mul_add(n int) (int, int) {
var tmp int
input1, input2 := n, n // 赋初值
ret1, ret3 := ,
ret2 := for input1 > {
ret1 = ret1 + input1
input1--
} // n! + ... + 3! + 2! + 1!;
for input2 > {
tmp = input2
for tmp > {
ret2 = ret2 * tmp
tmp--
} ret3 = ret3 + ret2
ret2 =
input2--
}
return ret1, ret3
}
exec:
go run termial_factorial.go
golang初识3 - func的更多相关文章
- golang初识5 - interface
1. interface-new (1) abstract format: type abstractName interface { method_name1 [return_type] } (2) ...
- golang初识4 - Go 并发
Go的CSP并发模型实现:M, P, G Go实现了两种并发形式.第一种是大家普遍认知的:多线程共享内存.其实就是Java或者C++等语言中的多线程开发.另外一种是Go语言特有的,也是Go语言推荐的: ...
- golang初识 和 变量,常量,iota
目录 一.go语言与python 1. go语言 2. python 二.变量相关 1. go语言的基本语法 2. 标识符和关键字 3. 变量声明 (1)声明变量时未指定初始值 (2)声明变量时指定初 ...
- golang初识2
1. 赋值与申明 str := "Hello, WebAssembly" // 简短声明 标准格式: var str string str = "Hello, WebAs ...
- golang初识 - install go on ubuntu
WSL: Ubuntu 18.04 1. install go (1) unzip sudo mkdir -p /usr/local/go sudo tar zxvf go1.12.4.linux-a ...
- 初始Golang
Golang初识 字节跳动也就是我们常说的今日头条 1.今日头条基于Go语言构建千亿级微服务的实践 今日头条当前后端服务超过80%的流量是跑在Go构建的服务上 微服务数量超过100个 高峰QPS超过7 ...
- golang使用 mongo
连接集群 mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?op ...
- Golang下通过syscall调用win32的dll(calling Windows DLLs from Go )
很多同学比如我虽然很喜欢golang,但是还是需要调用很多遗留项目或者其他优秀的开源项目,这时怎么办呢?我们想到的方法是用package里的syscall结合cgo 注意此处有坑: 在我调试时显示no ...
- Golang语言的入门开始
一.golang介绍与安装 二.golang-hello world 三.golang的变量 四.golang的类型 五.golang的常量 六.golang的函数(func) 七.golang的包 ...
随机推荐
- tp5.0隐藏路由后缀index.php
一开始的路由是有index.php结尾的 接下来开始修改主要文件
- java中字符串"1999-10-01T00:00:00+08: 00" 转化为Date格式
String oldStr = "1999-10-01T00:00:00+08: 00": SimpleDateFORMAT sdf = new SimpleDateFORMAT ...
- 锚点的animate使用过程中定位不准确的问题小记
源码: $('html, body, .S').animate({ scrollTop: $('.a1').offset().top - 133}, { duration: 1500, easing: ...
- auto-encoder小记
1.使用auto-encoder生成手写数字 2.中间code层使用二维向量,使用L2norm处理中间层数据 3.从[-1,1]的矩形框中等间隔选取100个坐标点 作为code值 最终生成图像 后期应 ...
- 对于Linux内核执行过程的理解(基于fork、execve、schedule等函数)
382 + 原创作品转载请注明出处 + https://github.com/mengning/linuxkernel/ 一.实验环境 win10 -> VMware -> Ubuntu1 ...
- Python 安装beautifulsoup4遇到No module named setuptools问题解决方法
背景说明: 电脑win7-32 在Python 3.3.5下安装beautifulsoup4 4.6.0(下载链接https://pypi.org/project/beautifulsoup4/#fi ...
- 实体lis<T>t转换datatable
public static DataTable ListToTable<T>(List<T> list) { Type type = typeof(T) ...
- C# 程序修改config文件后,不重启程序刷新配置ConfigurationManager
基本共识: ConfigurationManager 自带缓存,且不支持 写入. 如果 通过 文本写入方式 修改 配置文件,程序 无法刷新加载 最新配置. PS. Web.config 除外:Web. ...
- Metaclasses
1.Metaclasses Metaclasses是创建class(对象)的东西,它们是描述类的类,我们经常使用所理解的对象和class以及Metaclasses可以理解成以下形式: MyClass ...
- NLP VS NLU
NLP(Natural Language Processing )自然语言处理:是计算机科学,人工智能和语言学的交叉领域.目标是让计算机处理或“理解”自然语言,以执行语言翻译和问题回答等任务.NLU ...