1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

map に存在しない値を指定したときの挙動

Posted at

ゼロ値が出力される

package main

import "fmt"

func main() {
	m := make(map[string]int)

	// map に存在しない値
	a := m["あ"]

	fmt.Println(a) // 0
}

カンマokイディオムを使ったときも同様

package main

import "fmt"

func main() {
	m := make(map[string]int)

	// map に存在しない値
	b, ok := m["あ"]

	fmt.Println(b, ok) // 0 false
}

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?