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

推荐订阅源

J
Java Code Geeks
爱范儿
爱范儿
Attack and Defense Labs
Attack and Defense Labs
量子位
The GitHub Blog
The GitHub Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Scott Helme
Scott Helme
C
CXSECURITY Database RSS Feed - CXSecurity.com
博客园 - 叶小钗
C
Cybersecurity and Infrastructure Security Agency CISA
S
Securelist
S
Schneier on Security
C
Cisco Blogs
B
Blog RSS Feed
Cisco Talos Blog
Cisco Talos Blog
Last Week in AI
Last Week in AI
WordPress大学
WordPress大学
腾讯CDC
酷 壳 – CoolShell
酷 壳 – CoolShell
罗磊的独立博客
Y
Y Combinator Blog
Latest news
Latest news
T
Tailwind CSS Blog
Jina AI
Jina AI
宝玉的分享
宝玉的分享
人人都是产品经理
人人都是产品经理
C
CERT Recently Published Vulnerability Notes
D
Darknet – Hacking Tools, Hacker News & Cyber Security
L
Lohrmann on Cybersecurity
The Cloudflare Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Microsoft Security Blog
Microsoft Security Blog
H
Help Net Security
P
Palo Alto Networks Blog
V
V2EX
博客园_首页
D
Docker
T
Threat Research - Cisco Blogs
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
V
Vulnerabilities – Threatpost
月光博客
月光博客
D
DataBreaches.Net
Stack Overflow Blog
Stack Overflow Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Know Your Adversary
Know Your Adversary
L
LangChain Blog
The Hacker News
The Hacker News
K
Kaspersky official blog
The Register - Security
The Register - Security
NISL@THU
NISL@THU

博客园 - 甩掉裤衩凭风吹

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 博客园 - 甩掉裤衩凭风吹

6、If/Else

Go 中分支是直截了当的。ifelse

请注意,在 Go 中,您不需要在条件两边加上括号,但大括号是必需的。

在 Go 中没有三元组,因此即使对于基本条件,您也需要使用完整的语句。

$ go run switch.go 
Write 2 as two
It's a weekday
It's after noon
I'm a bool
I'm an int
Don't know type string

7、Switch

Switch跨多个分支表达条件。

可以使用逗号分隔同一语句中的多个表达式。

 

$ go run arrays.go
emp: [0 0 0 0 0]
set: [0 0 0 0 100]
get: 100
len: 5
dcl: [1 2 3 4 5]
2d:  [[0 1 2] [1 2 3]] 

8、Arrays

在 Go 中,数组是特定长度的元素的编号序列。

 

$ go run arrays.go
emp: [0 0 0 0 0]
set: [0 0 0 0 100]
get: 100
len: 5
dcl: [1 2 3 4 5]
2d:  [[0 1 2] [1 2 3]]

9、Slices

切片是 Go 中的关键数据类型,为序列提供了比数组更强大的接口。

 

$ go run slices.go
emp: [  ]
set: [a b c]
get: c
len: 3
apd: [a b c d e f]
cpy: [a b c d e f]
sl1: [c d e]
sl2: [a b c d e]
sl3: [c d e f]
dcl: [g h i]
2d:  [[0] [1 2] [2 3 4]]

10、Maps

Maps是 Go 的内置关联数据类型(有时在其他语言中称为哈希字典)。

 

$ go run maps.go 
map: map[k1:7 k2:13]
v1:  7
len: 2
map: map[k1:7]
prs: false
map: map[bar:2 foo:1]