dpxua26604 2017-08-05 22:33
浏览 28
已采纳

多个作业有顺序吗?

I know golang supports multiple assignment, for instance,

a, b = c, d

I want to know if the assignment following the left->right order? For instance, if I play with trees:

parent, child = child, child.child

Does it guarantee both parent and child are assigned one level deeper in the tree?

  • 写回答

1条回答 默认 最新

  • duan3019 2017-08-05 22:54
    关注

    Yes. From the language spec:

    The assignment proceeds in two phases. First, the operands of index expressions and pointer indirections (including implicit pointer indirections in selectors) on the left and the expressions on the right are all evaluated in the usual order. Second, the assignments are carried out in left-to-right order.

    So in your example, child and child.child will be evaluated first, then assigned to parent and child respectively.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题