判断方式为value,ok := map[key], ok为true则存在

package main

import "fmt"

func main() {

	demo := map[string]bool{
		"a": false,
	}

	//错误,a存在,但是返回false
	fmt.Println(demo["a"])

	//正确判断方法
	_, ok := demo["a"]
	fmt.Println(ok)
}

  

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-17
  • 2021-10-26
  • 2022-12-23
  • 2022-12-23
  • 2021-07-19
猜你喜欢
  • 2022-12-23
  • 2021-11-28
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-14
  • 2021-11-04
相关资源
相似解决方案