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

推荐订阅源

Help Net Security
Help Net Security
Recent Announcements
Recent Announcements
A
About on SuperTechFans
N
News and Events Feed by Topic
I
Intezer
B
Blog
GbyAI
GbyAI
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Project Zero
Project Zero
T
The Blog of Author Tim Ferriss
Blog — PlanetScale
Blog — PlanetScale
阮一峰的网络日志
阮一峰的网络日志
T
Troy Hunt's Blog
TaoSecurity Blog
TaoSecurity Blog
IT之家
IT之家
MyScale Blog
MyScale Blog
The Register - Security
The Register - Security
Cyberwarzone
Cyberwarzone
Y
Y Combinator Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
酷 壳 – CoolShell
酷 壳 – CoolShell
Stack Overflow Blog
Stack Overflow Blog
P
Privacy & Cybersecurity Law Blog
S
Secure Thoughts
MongoDB | Blog
MongoDB | Blog
N
Netflix TechBlog - Medium
Hacker News - Newest:
Hacker News - Newest: "LLM"
G
Google Developers Blog
罗磊的独立博客
博客园 - 聂微东
G
GRAHAM CLULEY
AWS News Blog
AWS News Blog
Google Online Security Blog
Google Online Security Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
H
Hacker News: Front Page
C
Check Point Blog
L
Lohrmann on Cybersecurity
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Spread Privacy
Spread Privacy
O
OpenAI News
T
Tor Project blog
P
Privacy International News Feed
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Attack and Defense Labs
Attack and Defense Labs
L
LINUX DO - 最新话题
Forbes - Security
Forbes - Security
云风的 BLOG
云风的 BLOG
C
Cisco Blogs
S
Securelist
博客园_首页

博客园 - 甩掉裤衩凭风吹

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]