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

后端 未结 8 1011
耶瑟儿~
耶瑟儿~ 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:48

    It is called the blank identifier and it helps in cases where you wish to discard the value that is going to be returned and not reference it

    Some places where we use it:

    • A function returns a value and you don't intend to use it in the future
    • You want to iterate and need an i value that you will not be using

提交回复
热议问题