SlideShare une entreprise Scribd logo
1  sur  58
Télécharger pour lire hors ligne
An Ultimate GopherLabs
Hands-on Labs
Types - slice, map, new, make, struct
• Docker Community Leader , Bangalore
• Author :- lightweight Kubernetes with k3s
with packt Publication
• Gopherlabs – 500+ tutorials
• Okteto – Kubernetes For Developer , Bangalore
Meetup Organizer
Who Am I?
@BiradarSangam
Sangam Biradar
EngineITops.com
https://golang.org/ref/spec
● slice
https://play.golang.org/p/pYxENZqmCOU
https://play.golang.org/p/9U46JgUx9zW
0 - a
1 - b
2 - c
3 - g
4 - m
5 - z
● making a Slice
https://play.golang.org/p/ZZVKKlFpSpC
0 Kannada - Shubhodava
1 Konkani - Dev Tuka Boro Dis Divum
2 Korean - Annyunghaseyo
3 Latvian - Labrit
4 Lithuanian – Labas Rytas
5 Macedonian - Dobro utro
6 Malayalam – Namaskaram
7 Maltese – L-Ghodwa t-Tajba
8 Mandarin – Nin hao
9 Marathi - Suprabhat
Kannada - Shubhodava
Konkani - Dev Tuka Boro Dis Divum
Korean - Annyunghaseyo
Latvian – Labrit
Lithuanian – Labas Rytas
Macedonian - Dobro utro
Malayalam – Namaskaram
Maltese – L-Ghodwa t-Tajba
Mandarin – Nin hao
Marathi - Suprabhat
● Slicing a Slices
https://play.golang.org/p/IKvj069CHzv
● making a slice
https://play.golang.org/p/r21LWwwQ9y-
If we think that our slice might grow, we can set a capacity larger than
length. This gives our slice room to grow without golang having to create
a new underlying array every time our slice grows. When the slice
exceeds capacity, then a new underlying array will be created. These arrays
double in size each time they’re created (2, 4, 8, 16) up to a certain point,
and then they scale in some smaller proportion.
● appending to slice
https://play.golang.org/p/dSDiSBTiJC7
● appending beyond capacity to a slice
https://play.golang.org/p/jJdMcszsJRM
If we think that our slice might grow, we can set a capacity larger than
length. This gives our slice room to grow without golang having to
create a new underlying array every time our slice grows. When the
slice exceeds capacity, then a new underlying array will be created.
These arrays typically double in size each time they’re created (2, 4, 8,
16).
● appending slice to a slice
notice the syntax
args...
https://play.golang.org/p/6OIh7zeM5Nj
● delete from Slice
https://play.golang.org/p/Z7H6GdPgDMy
● exercise
● write a program that creates a slice of ints
using shorthand notation then prints the slice
● write a program that creates a slice of strings
using shorthand notation then prints the slice
● create a slice of ints using make;set the length
to 5 and capacity to 10
● append a slice to a slice
● delete an element from a slice.
● Map [key , value]
● map
● basic info
○ key:value
○ maps keys to values
○ called “dictionaries” in some languages
○ built into the language (not an additional library
you must import) so they’re first-class citizens
● Map Keys
○ need to be unique
○ the type used for a key needs to have the
equality operator defined for it
■ the type must allow equals comparisons
■ can’t use these types
● slice
● map
● Maps are Reference Types
○ they behave like pointers
○ when you pass a map variable to a function
■ any changes to that mapped variable
in the function
■ change that original mapped variable
outside the function
● Maps are Not Thread Safe
○ best to avoid using maps concurrently
● Shorthand for Creating Map
https://play.golang.org/p/ptO8KjvdKNt
● adding an entry to a map
https://play.golang.org/p/Tia8HLGK3mD https://play.golang.org/p/0dZnCo440k7
● updating /delete an entry
https://play.golang.org/p/LbZJt2y8UFn https://play.golang.org/p/MAXxKaxgfnw
● comma-ok-idiom
check for existence
comma ok idiom
● comma-ok-idiom
check for existence
comma ok idiom
https://play.golang.org/p/f9LMgiobYMm
● range loop
https://play.golang.org/p/K0G_Etz_uVo
● make a map
https://play.golang.org/p/fTAwe3wEWoL
● exercise
create a program that:
● creates a map using shorthand notation
● adds an entry to the map
● changes an entry in the map
● deletes an entry in the map
● prints all of the entries in the map using range
● prints the len of the map
● uses the comma ok idiom
● make vs new
● make
○ slices, maps, channels
○ allocates memory
○ initializes
■ puts 0 or empty string into values
● new
○ returns a pointer
■ newly allocated
■ zeroed value
● “returns a pointer to a
newly allocated zeroed
value of type T”
https://play.golang.org/p/ij1aXv6J7HE
● new
○ returns a pointer
■ newly allocated
■ zeroed value
● “returns a pointer to a newly allocated
zeroed value of type T”
make vs new
● make
○ slices, maps, channels
○ allocates memory
○ initializes
■ puts 0 or empty string into values
https://play.golang.org/p/rKcc3Lv8bOY
● zero value
false for booleans, 0 for integers, 0.0 for floats, "" for strings
nil for pointers, functions, interfaces, slices, channels, and maps
● make vs new
● new
○ returns a pointer
■ newly allocated
■ zeroed value
● “returns a pointer to a newly
allocated zeroed value of type T”
● make
○ slices, maps, channels
○ allocates memory
○ initializes
■ puts 0 or empty string into values
https://play.golang.org/p/hYm8y3AiQDV
● make vs new
● make
○ slices, maps, channels
○ allocates memory
○ initializes
■ puts 0 or empty string into values
● new
○ returns a pointer
■ newly allocated
■ zeroed value
● “returns a pointer to a newly
allocated zeroed value of type T”
https://play.golang.org/p/zXpIGWTFP5A
● make vs new
● make
○ slices, maps, channels
○ allocates memory
○ initializes
■ puts 0 or empty string into values
https://play.golang.org/p/r77ksucKjSi
● new
○ returns a pointer
■ newly allocated
■ zeroed value
● “returns a pointer to a newly
allocated zeroed value of type T”
● make
○ slices, maps, channels
○ allocates memory
● initializes
■ puts 0 or empty string into values
● make vs new
https://play.golang.org/p/lhOc5lXQizU
● make vs new
● make
○ slices, maps, channels
○ allocates memory
● initializes
■ puts 0 or empty string into values
https://play.golang.org/p/RRyqZc8q0oI
● make vs new
● make
○ slices, maps, channels
○ allocates memory
● initializes
■ puts 0 or empty string into values
https://play.golang.org/p/Z64HscwjFc_L
● make vs new
● make
○ slices, maps, channels
○ allocates memory
● initializes
■ puts 0 or empty string into values
https://play.golang.org/p/qI1mMyumewG
● exercise
create a program that:
● declares a variable of type int using new
○ (note: this is not idiomatic go code to create an int this way)
● print out the memory address of the variable
● print out the value of the variable
● true or false:
○ new returned a pointer
create a program that:
● declares a variable of type string using new
○ (note: this is not idiomatic go code to create an string this way)
● print out the memory address of the variable
● print out the value of the variable
● true or false:
○ new returned a pointer
● exercise
create a program that:
● declares a variable of type bool using new
○ (note: this is not idiomatic go code to create an bool this way)
● print out the memory address of the variable
● print out the value of the variable
● true or false:
○ new returned a pointer
● exercise
create a program that:
● declares a variable of type[]int using make
● print out the value of the variable
● true or false:
○ make returned a pointer
create a program that:
● declares a variable of type map[int]string using make
● print out the value of the variable
● true or false:
○ make returned a pointer
● What are the zeroed values for int, string,
bool?
● What are the zeroed values for slice and map
● Explain the difference between make and
new
● struct – grouped fields
create a struct
and initialize it
https://play.golang.org/p/UJ1xEwy4VOP
accessing fields using
dot notation
https://play.golang.org/p/rb1oslM6Y3r
accessing fields using
dot notation
initialize a variable
naming the fields
https://play.golang.org/p/sV4dqi5UJI-
initialize a variable
omitting fields
https://play.golang.org/p/I4hJzlyQurZ
viewing the type
of p1
We have created our own type
which is interesting to think about!
https://play.golang.org/p/FiT64-Cel9_m
taking the address of a struct
p1 is of type *person
https://play.golang.org/p/tSM8aNvoO4n
● new
○ returns a pointer
■ newly allocated
■ zeroed value
● “returns a pointer to a newly allocated zeroed
value of type T”
● question
Can we use make with a struct?
question
Can we use make with a struct?
no
make is for slices, maps, and channels
● make
○ slices, maps, channels
○ allocates memory
● initializes
■ puts 0 or empty string into values
https://play.golang.org/p/ysOO98tL_3t
https://play.golang.org/p/OBlHXTz3pEO
● exercise
create a program that:
● defines a struct type to hold customer info
● initialize two variables using that struct type
● uses dot-notation to print a field from each of
the variables
● changes the value of one of the fields
● prints the changed field
● Can you use new to create a variable of a
struct type?
● question
Can you use make to create a variable of a struct type?
● Review
● slice vs. slicing vs. index access
● slice
○ list
○ mySlice := []int{1, 3, 5, 7, 9, 11}
○ greeting := make([]string, 3, 5)
○ greeting = append(greeting, "Hello")
○ mySlice = append(mySlice, myOtherSlice...)
○ mySlice = append(mySlice[:2], mySlice[3:]...)
● map
○ key, value
■ key type, element type
○ initializing
■ myMap := map[int]string{<entries>}
■ otras := make(map[string]string)
○ adding new entry
■ otras[“new key”] = “new value”
○ changing entry
■ otras[“new key”] = “newer value”
○ delete entry
■ delete(otras, “new key”)
● comma ok idiom
○ if val, ok := myGreeting[2]; ok {
fmt.Println("val: ", val)
fmt.Println("exists: ", exists)
}
● make
○ slices, maps, channels
○ allocates memory
● initializes
■ puts 0 or empty string into values
● new
○ returns a pointer
■ newly allocated
■ zeroed value
● “returns a pointer to a newly
allocated zeroed value of
type T”
● struct
○ grouped fields
○ type person struct { name string age int
}
○ p1 := person{name: "James"}
● References
● https://gopherlabs.collabnix.com
● https://godoc.org/
● https://golang.org/doc/
Thanks!
Any questions?
@sangambiradar@BiradarSangamSangam Biradar

Contenu connexe

Tendances

Golang Performance : microbenchmarks, profilers, and a war story
Golang Performance : microbenchmarks, profilers, and a war storyGolang Performance : microbenchmarks, profilers, and a war story
Golang Performance : microbenchmarks, profilers, and a war storyAerospike
 
What is new with JavaScript in Gnome: The 2021 edition
What is new with JavaScript in Gnome: The 2021 editionWhat is new with JavaScript in Gnome: The 2021 edition
What is new with JavaScript in Gnome: The 2021 editionIgalia
 
Python performance engineering in 2017
Python performance engineering in 2017Python performance engineering in 2017
Python performance engineering in 2017Alex Chistyakov
 
Meetup #24 Docker for Node Developer
Meetup #24 Docker for Node DeveloperMeetup #24 Docker for Node Developer
Meetup #24 Docker for Node DeveloperMVP Microsoft
 
Goroutine stack and local variable allocation in Go
Goroutine stack and local variable allocation in GoGoroutine stack and local variable allocation in Go
Goroutine stack and local variable allocation in GoYu-Shuan Hsieh
 
Testing Django APIs
Testing Django APIsTesting Django APIs
Testing Django APIstyomo4ka
 
Caching in Docker - the hardest thing in computer science
Caching in Docker - the hardest thing in computer scienceCaching in Docker - the hardest thing in computer science
Caching in Docker - the hardest thing in computer scienceJarek Potiuk
 
How go makes us faster (May 2015)
How go makes us faster (May 2015)How go makes us faster (May 2015)
How go makes us faster (May 2015)Wilfried Schobeiri
 
Austin Python Meetup 2017: What's New in Pythons 3.5 and 3.6?
Austin Python Meetup 2017: What's New in Pythons 3.5 and 3.6?Austin Python Meetup 2017: What's New in Pythons 3.5 and 3.6?
Austin Python Meetup 2017: What's New in Pythons 3.5 and 3.6?Viach Kakovskyi
 
Kopf @ Python Pizza Berlin, 2019-08-23
Kopf @ Python Pizza Berlin, 2019-08-23Kopf @ Python Pizza Berlin, 2019-08-23
Kopf @ Python Pizza Berlin, 2019-08-23Sergey Vasilyev
 
PyCon Poland 2016: Maintaining a high load Python project: typical mistakes
PyCon Poland 2016: Maintaining a high load Python project: typical mistakesPyCon Poland 2016: Maintaining a high load Python project: typical mistakes
PyCon Poland 2016: Maintaining a high load Python project: typical mistakesViach Kakovskyi
 
Reproducible Environments for Reproducible Results - PyOhio 2018
Reproducible Environments for Reproducible Results - PyOhio 2018Reproducible Environments for Reproducible Results - PyOhio 2018
Reproducible Environments for Reproducible Results - PyOhio 2018Dana Walker
 
Plasmaquick Workshop - FISL 13
Plasmaquick Workshop - FISL 13Plasmaquick Workshop - FISL 13
Plasmaquick Workshop - FISL 13Daker Fernandes
 
Server Development Workflow For PicCollage
Server Development Workflow For PicCollageServer Development Workflow For PicCollage
Server Development Workflow For PicCollageLin Jen-Shin
 
Theming Plone with Deliverance
Theming Plone with DeliveranceTheming Plone with Deliverance
Theming Plone with DeliveranceRok Garbas
 
The Robot under dictate of the LegoMindStorm Java Concurrency API
The Robot under dictate of the LegoMindStorm Java Concurrency APIThe Robot under dictate of the LegoMindStorm Java Concurrency API
The Robot under dictate of the LegoMindStorm Java Concurrency APIMiro Wengner
 
Last Month in PHP - April 2017
Last Month in PHP - April 2017Last Month in PHP - April 2017
Last Month in PHP - April 2017Eric Poe
 
Kernel Recipes 2018 - Live (Kernel) Patching: status quo and status futurus -...
Kernel Recipes 2018 - Live (Kernel) Patching: status quo and status futurus -...Kernel Recipes 2018 - Live (Kernel) Patching: status quo and status futurus -...
Kernel Recipes 2018 - Live (Kernel) Patching: status quo and status futurus -...Anne Nicolas
 
Run Go applications on Pico using TinyGo
Run Go applications on Pico using TinyGo Run Go applications on Pico using TinyGo
Run Go applications on Pico using TinyGo Yu-Shuan Hsieh
 

Tendances (20)

Golang Performance : microbenchmarks, profilers, and a war story
Golang Performance : microbenchmarks, profilers, and a war storyGolang Performance : microbenchmarks, profilers, and a war story
Golang Performance : microbenchmarks, profilers, and a war story
 
What is new with JavaScript in Gnome: The 2021 edition
What is new with JavaScript in Gnome: The 2021 editionWhat is new with JavaScript in Gnome: The 2021 edition
What is new with JavaScript in Gnome: The 2021 edition
 
Python performance engineering in 2017
Python performance engineering in 2017Python performance engineering in 2017
Python performance engineering in 2017
 
Meetup #24 Docker for Node Developer
Meetup #24 Docker for Node DeveloperMeetup #24 Docker for Node Developer
Meetup #24 Docker for Node Developer
 
Goroutine stack and local variable allocation in Go
Goroutine stack and local variable allocation in GoGoroutine stack and local variable allocation in Go
Goroutine stack and local variable allocation in Go
 
Testing Django APIs
Testing Django APIsTesting Django APIs
Testing Django APIs
 
Paris.py
Paris.pyParis.py
Paris.py
 
Caching in Docker - the hardest thing in computer science
Caching in Docker - the hardest thing in computer scienceCaching in Docker - the hardest thing in computer science
Caching in Docker - the hardest thing in computer science
 
How go makes us faster (May 2015)
How go makes us faster (May 2015)How go makes us faster (May 2015)
How go makes us faster (May 2015)
 
Austin Python Meetup 2017: What's New in Pythons 3.5 and 3.6?
Austin Python Meetup 2017: What's New in Pythons 3.5 and 3.6?Austin Python Meetup 2017: What's New in Pythons 3.5 and 3.6?
Austin Python Meetup 2017: What's New in Pythons 3.5 and 3.6?
 
Kopf @ Python Pizza Berlin, 2019-08-23
Kopf @ Python Pizza Berlin, 2019-08-23Kopf @ Python Pizza Berlin, 2019-08-23
Kopf @ Python Pizza Berlin, 2019-08-23
 
PyCon Poland 2016: Maintaining a high load Python project: typical mistakes
PyCon Poland 2016: Maintaining a high load Python project: typical mistakesPyCon Poland 2016: Maintaining a high load Python project: typical mistakes
PyCon Poland 2016: Maintaining a high load Python project: typical mistakes
 
Reproducible Environments for Reproducible Results - PyOhio 2018
Reproducible Environments for Reproducible Results - PyOhio 2018Reproducible Environments for Reproducible Results - PyOhio 2018
Reproducible Environments for Reproducible Results - PyOhio 2018
 
Plasmaquick Workshop - FISL 13
Plasmaquick Workshop - FISL 13Plasmaquick Workshop - FISL 13
Plasmaquick Workshop - FISL 13
 
Server Development Workflow For PicCollage
Server Development Workflow For PicCollageServer Development Workflow For PicCollage
Server Development Workflow For PicCollage
 
Theming Plone with Deliverance
Theming Plone with DeliveranceTheming Plone with Deliverance
Theming Plone with Deliverance
 
The Robot under dictate of the LegoMindStorm Java Concurrency API
The Robot under dictate of the LegoMindStorm Java Concurrency APIThe Robot under dictate of the LegoMindStorm Java Concurrency API
The Robot under dictate of the LegoMindStorm Java Concurrency API
 
Last Month in PHP - April 2017
Last Month in PHP - April 2017Last Month in PHP - April 2017
Last Month in PHP - April 2017
 
Kernel Recipes 2018 - Live (Kernel) Patching: status quo and status futurus -...
Kernel Recipes 2018 - Live (Kernel) Patching: status quo and status futurus -...Kernel Recipes 2018 - Live (Kernel) Patching: status quo and status futurus -...
Kernel Recipes 2018 - Live (Kernel) Patching: status quo and status futurus -...
 
Run Go applications on Pico using TinyGo
Run Go applications on Pico using TinyGo Run Go applications on Pico using TinyGo
Run Go applications on Pico using TinyGo
 

Similaire à Types - slice, map, new, make, struct - Gopherlabs

Blueprints: Introduction to Python programming
Blueprints: Introduction to Python programmingBlueprints: Introduction to Python programming
Blueprints: Introduction to Python programmingBhalaji Nagarajan
 
R programming for data science
R programming for data scienceR programming for data science
R programming for data scienceSovello Hildebrand
 
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介Wen Liao
 
Computer Graphics - Lecture 01 - 3D Programming I
Computer Graphics - Lecture 01 - 3D Programming IComputer Graphics - Lecture 01 - 3D Programming I
Computer Graphics - Lecture 01 - 3D Programming I💻 Anton Gerdelan
 
EuroPython 2013 - FAST, DOCUMENTED AND RELIABLE JSON BASED WEBSERVICES WITH P...
EuroPython 2013 - FAST, DOCUMENTED AND RELIABLE JSON BASED WEBSERVICES WITH P...EuroPython 2013 - FAST, DOCUMENTED AND RELIABLE JSON BASED WEBSERVICES WITH P...
EuroPython 2013 - FAST, DOCUMENTED AND RELIABLE JSON BASED WEBSERVICES WITH P...Alessandro Molina
 
spaGO: A self-contained ML & NLP library in GO
spaGO: A self-contained ML & NLP library in GOspaGO: A self-contained ML & NLP library in GO
spaGO: A self-contained ML & NLP library in GOMatteo Grella
 
Advanced Cartography for the Web
Advanced Cartography for the WebAdvanced Cartography for the Web
Advanced Cartography for the WebFOSS4G 2011
 
GraphQL Meetup Bangkok 4.0
GraphQL Meetup Bangkok 4.0GraphQL Meetup Bangkok 4.0
GraphQL Meetup Bangkok 4.0Tobias Meixner
 
Web Traffic Time Series Forecasting
Web Traffic  Time Series ForecastingWeb Traffic  Time Series Forecasting
Web Traffic Time Series ForecastingBillTubbs
 
OQGraph at MySQL Users Conference 2011
OQGraph at MySQL Users Conference 2011OQGraph at MySQL Users Conference 2011
OQGraph at MySQL Users Conference 2011Antony T Curtis
 
Formalising Graph Pattern Matching Gremlin traversals in Graph Alegra
Formalising Graph Pattern Matching Gremlin traversals in Graph AlegraFormalising Graph Pattern Matching Gremlin traversals in Graph Alegra
Formalising Graph Pattern Matching Gremlin traversals in Graph AlegraHarsh Thakkar
 
Introduction to plotting in Python
Introduction to plotting in Python Introduction to plotting in Python
Introduction to plotting in Python bzamecnik
 
Precog & MongoDB User Group: Skyrocket Your Analytics
Precog & MongoDB User Group: Skyrocket Your Analytics Precog & MongoDB User Group: Skyrocket Your Analytics
Precog & MongoDB User Group: Skyrocket Your Analytics MongoDB
 
BlaBlaCar Elastic Search Feedback
BlaBlaCar Elastic Search FeedbackBlaBlaCar Elastic Search Feedback
BlaBlaCar Elastic Search Feedbacksinfomicien
 
OQGraph @ SCaLE 11x 2013
OQGraph @ SCaLE 11x 2013OQGraph @ SCaLE 11x 2013
OQGraph @ SCaLE 11x 2013Antony T Curtis
 
AOT-compilation of JavaScript with V8
AOT-compilation of JavaScript with V8AOT-compilation of JavaScript with V8
AOT-compilation of JavaScript with V8Phil Eaton
 

Similaire à Types - slice, map, new, make, struct - Gopherlabs (20)

Blueprints: Introduction to Python programming
Blueprints: Introduction to Python programmingBlueprints: Introduction to Python programming
Blueprints: Introduction to Python programming
 
R programming for data science
R programming for data scienceR programming for data science
R programming for data science
 
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
 
Computer Graphics - Lecture 01 - 3D Programming I
Computer Graphics - Lecture 01 - 3D Programming IComputer Graphics - Lecture 01 - 3D Programming I
Computer Graphics - Lecture 01 - 3D Programming I
 
Go. why it goes v2
Go. why it goes v2Go. why it goes v2
Go. why it goes v2
 
EuroPython 2013 - FAST, DOCUMENTED AND RELIABLE JSON BASED WEBSERVICES WITH P...
EuroPython 2013 - FAST, DOCUMENTED AND RELIABLE JSON BASED WEBSERVICES WITH P...EuroPython 2013 - FAST, DOCUMENTED AND RELIABLE JSON BASED WEBSERVICES WITH P...
EuroPython 2013 - FAST, DOCUMENTED AND RELIABLE JSON BASED WEBSERVICES WITH P...
 
spaGO: A self-contained ML & NLP library in GO
spaGO: A self-contained ML & NLP library in GOspaGO: A self-contained ML & NLP library in GO
spaGO: A self-contained ML & NLP library in GO
 
Advanced Cartography for the Web
Advanced Cartography for the WebAdvanced Cartography for the Web
Advanced Cartography for the Web
 
GraphQL Meetup Bangkok 4.0
GraphQL Meetup Bangkok 4.0GraphQL Meetup Bangkok 4.0
GraphQL Meetup Bangkok 4.0
 
Web Traffic Time Series Forecasting
Web Traffic  Time Series ForecastingWeb Traffic  Time Series Forecasting
Web Traffic Time Series Forecasting
 
OQGraph at MySQL Users Conference 2011
OQGraph at MySQL Users Conference 2011OQGraph at MySQL Users Conference 2011
OQGraph at MySQL Users Conference 2011
 
Formalising Graph Pattern Matching Gremlin traversals in Graph Alegra
Formalising Graph Pattern Matching Gremlin traversals in Graph AlegraFormalising Graph Pattern Matching Gremlin traversals in Graph Alegra
Formalising Graph Pattern Matching Gremlin traversals in Graph Alegra
 
Bitcoin:Next
Bitcoin:NextBitcoin:Next
Bitcoin:Next
 
Python 3 - tutorial
Python 3 - tutorialPython 3 - tutorial
Python 3 - tutorial
 
Introduction to plotting in Python
Introduction to plotting in Python Introduction to plotting in Python
Introduction to plotting in Python
 
Google V8 engine
Google V8 engineGoogle V8 engine
Google V8 engine
 
Precog & MongoDB User Group: Skyrocket Your Analytics
Precog & MongoDB User Group: Skyrocket Your Analytics Precog & MongoDB User Group: Skyrocket Your Analytics
Precog & MongoDB User Group: Skyrocket Your Analytics
 
BlaBlaCar Elastic Search Feedback
BlaBlaCar Elastic Search FeedbackBlaBlaCar Elastic Search Feedback
BlaBlaCar Elastic Search Feedback
 
OQGraph @ SCaLE 11x 2013
OQGraph @ SCaLE 11x 2013OQGraph @ SCaLE 11x 2013
OQGraph @ SCaLE 11x 2013
 
AOT-compilation of JavaScript with V8
AOT-compilation of JavaScript with V8AOT-compilation of JavaScript with V8
AOT-compilation of JavaScript with V8
 

Plus de sangam biradar

Terrascan - Cloud Native Security Tool
Terrascan - Cloud Native Security Tool Terrascan - Cloud Native Security Tool
Terrascan - Cloud Native Security Tool sangam biradar
 
Dockerize Spago Self Contained ML & NLP Library & Deploy on Okteto Cloud Usin...
Dockerize Spago Self Contained ML & NLP Library & Deploy on Okteto Cloud Usin...Dockerize Spago Self Contained ML & NLP Library & Deploy on Okteto Cloud Usin...
Dockerize Spago Self Contained ML & NLP Library & Deploy on Okteto Cloud Usin...sangam biradar
 
XCloudLabs- AWS Overview
XCloudLabs- AWS Overview XCloudLabs- AWS Overview
XCloudLabs- AWS Overview sangam biradar
 
Okteto For Kubernetes Developer :- Container Camp 2020
Okteto For Kubernetes Developer :- Container Camp 2020 Okteto For Kubernetes Developer :- Container Camp 2020
Okteto For Kubernetes Developer :- Container Camp 2020 sangam biradar
 
Happy Helming With Okteto
Happy Helming With OktetoHappy Helming With Okteto
Happy Helming With Oktetosangam biradar
 
5 cool ways to get started with Cloud Native Development ( with Okteto)
5 cool ways to get started with Cloud Native Development ( with Okteto)5 cool ways to get started with Cloud Native Development ( with Okteto)
5 cool ways to get started with Cloud Native Development ( with Okteto)sangam biradar
 
Docker + Tenserflow + GOlang - Golang singapore Meetup
Docker + Tenserflow + GOlang - Golang singapore MeetupDocker + Tenserflow + GOlang - Golang singapore Meetup
Docker + Tenserflow + GOlang - Golang singapore Meetupsangam biradar
 
kikstart journey of Golang with Hello world - Gopherlabs
kikstart journey of Golang with Hello world - Gopherlabs kikstart journey of Golang with Hello world - Gopherlabs
kikstart journey of Golang with Hello world - Gopherlabs sangam biradar
 
funcs, func expressions, closure, returning funcs, recursion, the stack -goph...
funcs, func expressions, closure, returning funcs, recursion, the stack -goph...funcs, func expressions, closure, returning funcs, recursion, the stack -goph...
funcs, func expressions, closure, returning funcs, recursion, the stack -goph...sangam biradar
 
Cloud Native Okteto Cloud
Cloud Native Okteto Cloud Cloud Native Okteto Cloud
Cloud Native Okteto Cloud sangam biradar
 
Google ko: fast Kubernetes microservice development in Go - Sangam Biradar, E...
Google ko: fast Kubernetes microservice development in Go - Sangam Biradar, E...Google ko: fast Kubernetes microservice development in Go - Sangam Biradar, E...
Google ko: fast Kubernetes microservice development in Go - Sangam Biradar, E...sangam biradar
 
welcome to gopherlabs - why go (golang)?
welcome to gopherlabs - why go (golang)?welcome to gopherlabs - why go (golang)?
welcome to gopherlabs - why go (golang)?sangam biradar
 
Rabncher Meetup India , Lightweight Kubernetes Development with K3s, k3os and...
Rabncher Meetup India , Lightweight Kubernetes Development with K3s, k3os and...Rabncher Meetup India , Lightweight Kubernetes Development with K3s, k3os and...
Rabncher Meetup India , Lightweight Kubernetes Development with K3s, k3os and...sangam biradar
 
TensorFlow, Docker & GoLang - All for Image Rekognition Sangam Biradar(Engine...
TensorFlow, Docker & GoLang - All for Image Rekognition Sangam Biradar(Engine...TensorFlow, Docker & GoLang - All for Image Rekognition Sangam Biradar(Engine...
TensorFlow, Docker & GoLang - All for Image Rekognition Sangam Biradar(Engine...sangam biradar
 
Introducing Pico - A Deep Learning Platform using Docker & IoT - Sangam Biradar
Introducing Pico - A Deep Learning Platform using Docker & IoT - Sangam BiradarIntroducing Pico - A Deep Learning Platform using Docker & IoT - Sangam Biradar
Introducing Pico - A Deep Learning Platform using Docker & IoT - Sangam Biradarsangam biradar
 
September 7, 2019 Cloud Native and Containerisation (Joint Meetup with Docke...
September 7, 2019  Cloud Native and Containerisation (Joint Meetup with Docke...September 7, 2019  Cloud Native and Containerisation (Joint Meetup with Docke...
September 7, 2019 Cloud Native and Containerisation (Joint Meetup with Docke...sangam biradar
 
Implementing Lightweight Kubernetes(K3s) on Raspberry Pi Stack - Sangam Biradar
Implementing Lightweight Kubernetes(K3s) on Raspberry Pi Stack - Sangam BiradarImplementing Lightweight Kubernetes(K3s) on Raspberry Pi Stack - Sangam Biradar
Implementing Lightweight Kubernetes(K3s) on Raspberry Pi Stack - Sangam Biradarsangam biradar
 
Docker on IOT - Dockercon19 SFO Recap & Announcements, Bangalore
Docker on IOT - Dockercon19 SFO Recap & Announcements, BangaloreDocker on IOT - Dockercon19 SFO Recap & Announcements, Bangalore
Docker on IOT - Dockercon19 SFO Recap & Announcements, Bangaloresangam biradar
 

Plus de sangam biradar (19)

Terrascan - Cloud Native Security Tool
Terrascan - Cloud Native Security Tool Terrascan - Cloud Native Security Tool
Terrascan - Cloud Native Security Tool
 
Dockerize Spago Self Contained ML & NLP Library & Deploy on Okteto Cloud Usin...
Dockerize Spago Self Contained ML & NLP Library & Deploy on Okteto Cloud Usin...Dockerize Spago Self Contained ML & NLP Library & Deploy on Okteto Cloud Usin...
Dockerize Spago Self Contained ML & NLP Library & Deploy on Okteto Cloud Usin...
 
XCloudLabs- AWS Overview
XCloudLabs- AWS Overview XCloudLabs- AWS Overview
XCloudLabs- AWS Overview
 
Rustlabs Quick Start
Rustlabs Quick StartRustlabs Quick Start
Rustlabs Quick Start
 
Okteto For Kubernetes Developer :- Container Camp 2020
Okteto For Kubernetes Developer :- Container Camp 2020 Okteto For Kubernetes Developer :- Container Camp 2020
Okteto For Kubernetes Developer :- Container Camp 2020
 
Happy Helming With Okteto
Happy Helming With OktetoHappy Helming With Okteto
Happy Helming With Okteto
 
5 cool ways to get started with Cloud Native Development ( with Okteto)
5 cool ways to get started with Cloud Native Development ( with Okteto)5 cool ways to get started with Cloud Native Development ( with Okteto)
5 cool ways to get started with Cloud Native Development ( with Okteto)
 
Docker + Tenserflow + GOlang - Golang singapore Meetup
Docker + Tenserflow + GOlang - Golang singapore MeetupDocker + Tenserflow + GOlang - Golang singapore Meetup
Docker + Tenserflow + GOlang - Golang singapore Meetup
 
kikstart journey of Golang with Hello world - Gopherlabs
kikstart journey of Golang with Hello world - Gopherlabs kikstart journey of Golang with Hello world - Gopherlabs
kikstart journey of Golang with Hello world - Gopherlabs
 
funcs, func expressions, closure, returning funcs, recursion, the stack -goph...
funcs, func expressions, closure, returning funcs, recursion, the stack -goph...funcs, func expressions, closure, returning funcs, recursion, the stack -goph...
funcs, func expressions, closure, returning funcs, recursion, the stack -goph...
 
Cloud Native Okteto Cloud
Cloud Native Okteto Cloud Cloud Native Okteto Cloud
Cloud Native Okteto Cloud
 
Google ko: fast Kubernetes microservice development in Go - Sangam Biradar, E...
Google ko: fast Kubernetes microservice development in Go - Sangam Biradar, E...Google ko: fast Kubernetes microservice development in Go - Sangam Biradar, E...
Google ko: fast Kubernetes microservice development in Go - Sangam Biradar, E...
 
welcome to gopherlabs - why go (golang)?
welcome to gopherlabs - why go (golang)?welcome to gopherlabs - why go (golang)?
welcome to gopherlabs - why go (golang)?
 
Rabncher Meetup India , Lightweight Kubernetes Development with K3s, k3os and...
Rabncher Meetup India , Lightweight Kubernetes Development with K3s, k3os and...Rabncher Meetup India , Lightweight Kubernetes Development with K3s, k3os and...
Rabncher Meetup India , Lightweight Kubernetes Development with K3s, k3os and...
 
TensorFlow, Docker & GoLang - All for Image Rekognition Sangam Biradar(Engine...
TensorFlow, Docker & GoLang - All for Image Rekognition Sangam Biradar(Engine...TensorFlow, Docker & GoLang - All for Image Rekognition Sangam Biradar(Engine...
TensorFlow, Docker & GoLang - All for Image Rekognition Sangam Biradar(Engine...
 
Introducing Pico - A Deep Learning Platform using Docker & IoT - Sangam Biradar
Introducing Pico - A Deep Learning Platform using Docker & IoT - Sangam BiradarIntroducing Pico - A Deep Learning Platform using Docker & IoT - Sangam Biradar
Introducing Pico - A Deep Learning Platform using Docker & IoT - Sangam Biradar
 
September 7, 2019 Cloud Native and Containerisation (Joint Meetup with Docke...
September 7, 2019  Cloud Native and Containerisation (Joint Meetup with Docke...September 7, 2019  Cloud Native and Containerisation (Joint Meetup with Docke...
September 7, 2019 Cloud Native and Containerisation (Joint Meetup with Docke...
 
Implementing Lightweight Kubernetes(K3s) on Raspberry Pi Stack - Sangam Biradar
Implementing Lightweight Kubernetes(K3s) on Raspberry Pi Stack - Sangam BiradarImplementing Lightweight Kubernetes(K3s) on Raspberry Pi Stack - Sangam Biradar
Implementing Lightweight Kubernetes(K3s) on Raspberry Pi Stack - Sangam Biradar
 
Docker on IOT - Dockercon19 SFO Recap & Announcements, Bangalore
Docker on IOT - Dockercon19 SFO Recap & Announcements, BangaloreDocker on IOT - Dockercon19 SFO Recap & Announcements, Bangalore
Docker on IOT - Dockercon19 SFO Recap & Announcements, Bangalore
 

Dernier

Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 

Dernier (20)

Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 

Types - slice, map, new, make, struct - Gopherlabs

  • 1. An Ultimate GopherLabs Hands-on Labs Types - slice, map, new, make, struct
  • 2. • Docker Community Leader , Bangalore • Author :- lightweight Kubernetes with k3s with packt Publication • Gopherlabs – 500+ tutorials • Okteto – Kubernetes For Developer , Bangalore Meetup Organizer Who Am I? @BiradarSangam Sangam Biradar EngineITops.com
  • 5.
  • 6. https://play.golang.org/p/9U46JgUx9zW 0 - a 1 - b 2 - c 3 - g 4 - m 5 - z
  • 7. ● making a Slice https://play.golang.org/p/ZZVKKlFpSpC 0 Kannada - Shubhodava 1 Konkani - Dev Tuka Boro Dis Divum 2 Korean - Annyunghaseyo 3 Latvian - Labrit 4 Lithuanian – Labas Rytas 5 Macedonian - Dobro utro 6 Malayalam – Namaskaram 7 Maltese – L-Ghodwa t-Tajba 8 Mandarin – Nin hao 9 Marathi - Suprabhat Kannada - Shubhodava Konkani - Dev Tuka Boro Dis Divum Korean - Annyunghaseyo Latvian – Labrit Lithuanian – Labas Rytas Macedonian - Dobro utro Malayalam – Namaskaram Maltese – L-Ghodwa t-Tajba Mandarin – Nin hao Marathi - Suprabhat
  • 8. ● Slicing a Slices https://play.golang.org/p/IKvj069CHzv
  • 9. ● making a slice https://play.golang.org/p/r21LWwwQ9y- If we think that our slice might grow, we can set a capacity larger than length. This gives our slice room to grow without golang having to create a new underlying array every time our slice grows. When the slice exceeds capacity, then a new underlying array will be created. These arrays double in size each time they’re created (2, 4, 8, 16) up to a certain point, and then they scale in some smaller proportion.
  • 10. ● appending to slice https://play.golang.org/p/dSDiSBTiJC7
  • 11. ● appending beyond capacity to a slice https://play.golang.org/p/jJdMcszsJRM If we think that our slice might grow, we can set a capacity larger than length. This gives our slice room to grow without golang having to create a new underlying array every time our slice grows. When the slice exceeds capacity, then a new underlying array will be created. These arrays typically double in size each time they’re created (2, 4, 8, 16).
  • 12. ● appending slice to a slice notice the syntax args... https://play.golang.org/p/6OIh7zeM5Nj
  • 13. ● delete from Slice https://play.golang.org/p/Z7H6GdPgDMy
  • 14. ● exercise ● write a program that creates a slice of ints using shorthand notation then prints the slice ● write a program that creates a slice of strings using shorthand notation then prints the slice ● create a slice of ints using make;set the length to 5 and capacity to 10 ● append a slice to a slice ● delete an element from a slice.
  • 15. ● Map [key , value]
  • 16. ● map ● basic info ○ key:value ○ maps keys to values ○ called “dictionaries” in some languages ○ built into the language (not an additional library you must import) so they’re first-class citizens ● Map Keys ○ need to be unique ○ the type used for a key needs to have the equality operator defined for it ■ the type must allow equals comparisons ■ can’t use these types ● slice ● map ● Maps are Reference Types ○ they behave like pointers ○ when you pass a map variable to a function ■ any changes to that mapped variable in the function ■ change that original mapped variable outside the function ● Maps are Not Thread Safe ○ best to avoid using maps concurrently
  • 17. ● Shorthand for Creating Map https://play.golang.org/p/ptO8KjvdKNt
  • 18. ● adding an entry to a map https://play.golang.org/p/Tia8HLGK3mD https://play.golang.org/p/0dZnCo440k7
  • 19. ● updating /delete an entry https://play.golang.org/p/LbZJt2y8UFn https://play.golang.org/p/MAXxKaxgfnw
  • 20. ● comma-ok-idiom check for existence comma ok idiom
  • 21. ● comma-ok-idiom check for existence comma ok idiom https://play.golang.org/p/f9LMgiobYMm
  • 23. ● make a map https://play.golang.org/p/fTAwe3wEWoL
  • 24. ● exercise create a program that: ● creates a map using shorthand notation ● adds an entry to the map ● changes an entry in the map ● deletes an entry in the map ● prints all of the entries in the map using range ● prints the len of the map ● uses the comma ok idiom
  • 25. ● make vs new ● make ○ slices, maps, channels ○ allocates memory ○ initializes ■ puts 0 or empty string into values ● new ○ returns a pointer ■ newly allocated ■ zeroed value ● “returns a pointer to a newly allocated zeroed value of type T” https://play.golang.org/p/ij1aXv6J7HE
  • 26. ● new ○ returns a pointer ■ newly allocated ■ zeroed value ● “returns a pointer to a newly allocated zeroed value of type T” make vs new ● make ○ slices, maps, channels ○ allocates memory ○ initializes ■ puts 0 or empty string into values https://play.golang.org/p/rKcc3Lv8bOY
  • 27. ● zero value false for booleans, 0 for integers, 0.0 for floats, "" for strings nil for pointers, functions, interfaces, slices, channels, and maps
  • 28. ● make vs new ● new ○ returns a pointer ■ newly allocated ■ zeroed value ● “returns a pointer to a newly allocated zeroed value of type T” ● make ○ slices, maps, channels ○ allocates memory ○ initializes ■ puts 0 or empty string into values https://play.golang.org/p/hYm8y3AiQDV
  • 29. ● make vs new ● make ○ slices, maps, channels ○ allocates memory ○ initializes ■ puts 0 or empty string into values ● new ○ returns a pointer ■ newly allocated ■ zeroed value ● “returns a pointer to a newly allocated zeroed value of type T” https://play.golang.org/p/zXpIGWTFP5A
  • 30. ● make vs new ● make ○ slices, maps, channels ○ allocates memory ○ initializes ■ puts 0 or empty string into values https://play.golang.org/p/r77ksucKjSi ● new ○ returns a pointer ■ newly allocated ■ zeroed value ● “returns a pointer to a newly allocated zeroed value of type T”
  • 31. ● make ○ slices, maps, channels ○ allocates memory ● initializes ■ puts 0 or empty string into values ● make vs new https://play.golang.org/p/lhOc5lXQizU
  • 32. ● make vs new ● make ○ slices, maps, channels ○ allocates memory ● initializes ■ puts 0 or empty string into values https://play.golang.org/p/RRyqZc8q0oI
  • 33. ● make vs new ● make ○ slices, maps, channels ○ allocates memory ● initializes ■ puts 0 or empty string into values https://play.golang.org/p/Z64HscwjFc_L
  • 34. ● make vs new ● make ○ slices, maps, channels ○ allocates memory ● initializes ■ puts 0 or empty string into values https://play.golang.org/p/qI1mMyumewG
  • 35.
  • 36.
  • 37. ● exercise create a program that: ● declares a variable of type int using new ○ (note: this is not idiomatic go code to create an int this way) ● print out the memory address of the variable ● print out the value of the variable ● true or false: ○ new returned a pointer create a program that: ● declares a variable of type string using new ○ (note: this is not idiomatic go code to create an string this way) ● print out the memory address of the variable ● print out the value of the variable ● true or false: ○ new returned a pointer
  • 38. ● exercise create a program that: ● declares a variable of type bool using new ○ (note: this is not idiomatic go code to create an bool this way) ● print out the memory address of the variable ● print out the value of the variable ● true or false: ○ new returned a pointer
  • 39. ● exercise create a program that: ● declares a variable of type[]int using make ● print out the value of the variable ● true or false: ○ make returned a pointer create a program that: ● declares a variable of type map[int]string using make ● print out the value of the variable ● true or false: ○ make returned a pointer
  • 40. ● What are the zeroed values for int, string, bool? ● What are the zeroed values for slice and map ● Explain the difference between make and new
  • 41. ● struct – grouped fields create a struct and initialize it https://play.golang.org/p/UJ1xEwy4VOP
  • 42. accessing fields using dot notation https://play.golang.org/p/rb1oslM6Y3r
  • 44. initialize a variable naming the fields https://play.golang.org/p/sV4dqi5UJI-
  • 45. initialize a variable omitting fields https://play.golang.org/p/I4hJzlyQurZ
  • 46. viewing the type of p1 We have created our own type which is interesting to think about! https://play.golang.org/p/FiT64-Cel9_m
  • 47. taking the address of a struct p1 is of type *person https://play.golang.org/p/tSM8aNvoO4n
  • 48. ● new ○ returns a pointer ■ newly allocated ■ zeroed value ● “returns a pointer to a newly allocated zeroed value of type T”
  • 49. ● question Can we use make with a struct?
  • 50. question Can we use make with a struct? no make is for slices, maps, and channels ● make ○ slices, maps, channels ○ allocates memory ● initializes ■ puts 0 or empty string into values
  • 53.
  • 54. ● exercise create a program that: ● defines a struct type to hold customer info ● initialize two variables using that struct type ● uses dot-notation to print a field from each of the variables ● changes the value of one of the fields ● prints the changed field ● Can you use new to create a variable of a struct type?
  • 55. ● question Can you use make to create a variable of a struct type?
  • 56. ● Review ● slice vs. slicing vs. index access ● slice ○ list ○ mySlice := []int{1, 3, 5, 7, 9, 11} ○ greeting := make([]string, 3, 5) ○ greeting = append(greeting, "Hello") ○ mySlice = append(mySlice, myOtherSlice...) ○ mySlice = append(mySlice[:2], mySlice[3:]...) ● map ○ key, value ■ key type, element type ○ initializing ■ myMap := map[int]string{<entries>} ■ otras := make(map[string]string) ○ adding new entry ■ otras[“new key”] = “new value” ○ changing entry ■ otras[“new key”] = “newer value” ○ delete entry ■ delete(otras, “new key”) ● comma ok idiom ○ if val, ok := myGreeting[2]; ok { fmt.Println("val: ", val) fmt.Println("exists: ", exists) } ● make ○ slices, maps, channels ○ allocates memory ● initializes ■ puts 0 or empty string into values ● new ○ returns a pointer ■ newly allocated ■ zeroed value ● “returns a pointer to a newly allocated zeroed value of type T” ● struct ○ grouped fields ○ type person struct { name string age int } ○ p1 := person{name: "James"}
  • 57. ● References ● https://gopherlabs.collabnix.com ● https://godoc.org/ ● https://golang.org/doc/