惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - 甩掉裤衩凭风吹

Go学习例子(六) - 甩掉裤衩凭风吹 Go学习例子(五) - 甩掉裤衩凭风吹 Go学习例子(四) Go学习例子(二) Go学习例子(一) 一、Python基础语法 - 甩掉裤衩凭风吹 Python爬虫实战一之爬取糗事百科段子 Python爬虫系列:五、正则表达式 Python爬虫系列:四、Cookie的使用 - 甩掉裤衩凭风吹 python爬虫系列:三、URLError异常处理 - 甩掉裤衩凭风吹 python系列:二、Urllib库的高级用法 - 甩掉裤衩凭风吹 python系列:一、Urllib库的基本使用 - 甩掉裤衩凭风吹 二十七、mysql如何确保数据不丢失?有几点值得我们借鉴 二十六、聊聊mysql如何实现分布式锁 - 甩掉裤衩凭风吹 二十五、sql中where条件在数据库中提取与应用浅析 二十四、如何正确的使用索引? 二十三、mysql索引管理详解 二十二、mysql索引原理详解 二十一、什么是索引?
Go学习例子(三)
甩掉裤衩凭风吹 · 2021-11-30 · via 博客园 - 甩掉裤衩凭风吹

 11、Range

range循环访问各种数据结构中的元素。让我们看看如何使用我们已经学到的一些数据结构。

range在映射上迭代键/值对。

$ go run range.go
sum: 9
index: 1
a -> apple
b -> banana
key: a
key: b
0 103
1 111

12、Functions

功能是 Go 的核心。我们将通过几个不同的示例来了解函数。

$ go run functions.go 
1+2 = 3
1+2+3 = 6

3、Multiple Return Values

Go 内置了对多个返回值的支持。此功能经常在惯用 Go 中使用,例如从函数返回结果值和错误值。

如果只需要返回值的子集,请使用空白标识符 。_

go run multiple-return-values.go
3
7
7

14、Variadic Functions

可变参数函数可以使用任意数量的尾随参数进行调用。例如,是一个常见的可变参数函数。

可变参数函数可以用单个参数以通常的方式调用。

如果切片中已有多个 arg,请像这样将它们应用于可变参数函数。func(slice...)

 

go run variadic-functions.go 
[1 2] 3
[1 2 3] 6
[1 2 3 4] 10

15、Closures

Go支持匿名函数,可以形成闭包。当您想要内联定义函数而不必命名它时,匿名函数非常有用。

此函数返回另一个函数,我们在正文中匿名定义该函数。返回的函数在变量上闭合以形成闭包。

  

$ go run closures.go
1
2
3
1