英文:
Simultaneous assignment in Go
问题
我正在学习Go语言,有一件事我不太明白,为什么这门语言的创造者支持同时赋值?这样很容易出错,比如 a, b = a, b 而不是 a, b = b, a,我希望能得到一些好的解释,提前感谢。
英文:
I'm learning Go and can't understand one thing, why creators of this language do support simultaneous assignment? It is very easy to make mistakes like a, b = a, b and not a, b = b, a, as I would want, thanks in advance for any good explanations.
答案1
得分: 13
如果没有同时赋值的功能,那么你就需要采取其他方法。另一种替代方案可能是这样的:
tmp = a
a = b
b = tmp
这样做容易出错。
英文:
> It is very easy to make mistakes like a, b = a, b and not a, b = b, a,
If simultaneous assignment were not available then you would have to do something else instead. An alternative approach might look something like this:
tmp = a
a = b
b = tmp
That's much easier to get wrong.
答案2
得分: 8
你还能以什么方式获取函数的第二、第三、第四,以及更多的返回值呢?
英文:
How else would you get access to the second, third, fourth, … return value of a function?
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论