Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Go Arrays & Slices
Search
Nathan Youngman
May 25, 2015
Programming
0
150
Go Arrays & Slices
An overview of how slices and arrays work in Go.
Nathan Youngman
May 25, 2015
Tweet
Share
More Decks by Nathan Youngman
See All by Nathan Youngman
The Healthy Programmer
nathany
2
110
Go and Node.js: a comparison
nathany
1
240
Diet Hacks
nathany
2
390
Go 1.6 and HTTP/2
nathany
3
150
Upgrading Rails Redux
nathany
1
97
GopherCon recap
nathany
0
190
Go Functions
nathany
0
100
Go Types
nathany
2
140
Go Packages
nathany
2
560
Other Decks in Programming
See All in Programming
Best-Practices-for-Cortex-Analyst-and-AI-Agent
ryotaroikeda
1
110
CSC307 Lecture 10
javiergs
PRO
1
660
責任感のあるCloudWatchアラームを設計しよう
akihisaikeda
3
180
なぜSQLはAIぽく見えるのか/why does SQL look AI like
florets1
0
480
Smart Handoff/Pickup ガイド - Claude Code セッション管理
yukiigarashi
0
140
Lambda のコードストレージ容量に気をつけましょう
tattwan718
0
140
Amazon Bedrockを活用したRAGの品質管理パイプライン構築
tosuri13
5
770
AI & Enginnering
codelynx
0
120
AtCoder Conference 2025
shindannin
0
1.1k
【卒業研究】会話ログ分析によるユーザーごとの関心に応じた話題提案手法
momok47
0
200
SourceGeneratorのススメ
htkym
0
200
CSC307 Lecture 05
javiergs
PRO
0
500
Featured
See All Featured
Embracing the Ebb and Flow
colly
88
5k
RailsConf 2023
tenderlove
30
1.3k
Building Applications with DynamoDB
mza
96
6.9k
Statistics for Hackers
jakevdp
799
230k
Are puppies a ranking factor?
jonoalderson
1
2.7k
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
86
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
100
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
1
1.4k
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
1
1.3k
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
1.8k
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
260
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
231
22k
Transcript
gophers := [4]string{"blue", "pink", "purple", "blue"}
Arrays are fixed-length planets := [8]string{ "Mercury", "Venus", "Earth", "Mars",
"Jupiter", "Saturn", "Uranus", "Neptune", } 0 1 2 3 4 5 6 7
Arrays are values planetBackup := planets // make way
for an interstellar bypass planets[2] = “" fmt.Println(planets) // [Mercury Venus Mars Jupiter Saturn Uranus Neptune] fmt.Println(planetBackup) // [Mercury Venus Earth Mars Jupiter Saturn Uranus Neptune]
Slicing makes a window terrestrial := planets[0:4] gasGiants := planets[4:6]
iceGiants := planets[6:8] 0 1 2 3 4 5 6 7 terrestrial gasGiants iceGiants
Half-open range planets[2:3] // [Earth] < 3 • starts at
index 2 • excludes index 3
Defaults terrestrial := planets[:4] gasGiants := planets[4:6] iceGiants := planets[6:]
allPlanets := planets[:]
Making a slice // allPlanets := planets[:] planets := []string{
"Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune", }
Append to slices planets = append(planets, "Pluto") 0 1 2
3 4 5 6 7 8 9 10 11 12 13 14 15 fmt.Println(len(planets), cap(planets)) // 9 16
Append again planets = append(planets, "Eris", "Sedna") fmt.Println(len(planets), cap(planets))
// 11 16
http://blog.golang.org/go-slices-usage-and-internals https://github.com/golang/go/wiki/SliceTricks More reading