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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Nathan Youngman
May 25, 2015
Programming
170
0
Share
Go Arrays & Slices
An overview of how slices and arrays work in Go.
Nathan Youngman
May 25, 2015
More Decks by Nathan Youngman
See All by Nathan Youngman
The Healthy Programmer
nathany
2
120
Go and Node.js: a comparison
nathany
1
250
Diet Hacks
nathany
2
400
Go 1.6 and HTTP/2
nathany
3
160
Upgrading Rails Redux
nathany
1
100
GopherCon recap
nathany
0
190
Go Functions
nathany
0
110
Go Types
nathany
2
140
Go Packages
nathany
2
570
Other Decks in Programming
See All in Programming
ついに来た!本格的なマルチクラウド時代の Google Cloud
maroon1st
0
440
クラウドネイティブなエンジニアに向ける Raycastの魅力と実際の活用事例
nealle
2
260
【ディップ|26年新卒研修資料】TDD実装演習
dip_tech
PRO
0
190
AI時代になぜ書くのか
mutsumix
0
410
Are We Really Coding 10× Faster with AI?
kohzas
0
180
SREに優しいTerraform構成 modulesとstateの組み方
hiyanger
2
180
Sans tests, vos agents ne sont pas fiables
nabondance
0
130
AlarmKitで明後日起きれるアラームアプリを作る
trickart
0
140
Spec-Driven Development with AI Agents (Workshop, May 2026)
antonarhipov
3
360
TypeScriptだけでAIエージェントを作る フロント・エージェント・インフラのフルスタック実践
har1101
1
330
書き換えて学ぶTemporal #fukts
pirosikick
2
380
Agentic Elixir
whatyouhide
0
450
Featured
See All Featured
How to train your dragon (web standard)
notwaldorf
97
6.6k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
360
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
380
Chasing Engaging Ingredients in Design
codingconduct
0
190
Statistics for Hackers
jakevdp
799
230k
For a Future-Friendly Web
brad_frost
183
10k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
410
Deep Space Network (abreviated)
tonyrice
0
140
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.2k
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
1
220
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