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

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

    An unused variable is not allowed in Golang

    If you were coming from other programming languages this might feel bit difficult to get used to this. But this results in more cleaner code. So by using a _ we are saying we know there is a variable there but we don't want to use it and telling the compiler that does not complain me about it. :)

提交回复
热议问题