Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Accessing Map Values | Intro to Structs & Maps
course content

Conteúdo do Curso

Introduction to GoLang

Accessing Map ValuesAccessing Map Values

We can access the value corresponding to a key in a map using the following syntax:

go

index.go

For example:

go

index.go

The expression prices["apple"] essentially references the memory location where the value 100 is stored; hence, it acts like a variable. Therefore, we can edit the value stored at that key using the = operator:

go

index.go

We can use the same assignment syntax to create a new key in the map:

If the provided keyName doesn't exist in the map, it will create and add a new key to the map with the assigned value.

go

index.go

What will be the output of the following code?

Selecione a resposta correta

Tudo estava claro?

Seção 6. Capítulo 6
course content

Conteúdo do Curso

Introduction to GoLang

Accessing Map ValuesAccessing Map Values

We can access the value corresponding to a key in a map using the following syntax:

go

index.go

For example:

go

index.go

The expression prices["apple"] essentially references the memory location where the value 100 is stored; hence, it acts like a variable. Therefore, we can edit the value stored at that key using the = operator:

go

index.go

We can use the same assignment syntax to create a new key in the map:

If the provided keyName doesn't exist in the map, it will create and add a new key to the map with the assigned value.

go

index.go

What will be the output of the following code?

Selecione a resposta correta

Tudo estava claro?

Seção 6. Capítulo 6
some-alt