What is “_,” (underscore comma) in a Go declaration?

后端 未结 8 994
耶瑟儿~
耶瑟儿~ 2020-12-04 08:31

And I can\'t seem to understand this kind of variable declaration:

_, prs := m[\"example\"]

What exactly is \"_,\" doing and w

8条回答
  •  借酒劲吻你
    2020-12-04 08:33

    The blank identifier may be used whenever syntax requires a variable name but program logic does not, for instance to discard an unwanted loop index when we require only the element value.

    Excerpt From:

    The Go Programming Language (Addison-Wesley Professional Computing Series)

    Brian W. Kernighan

    This material may be protected by copyright.

提交回复
热议问题