What does “:=” do?

前端 未结 10 1727
别那么骄傲
别那么骄傲 2020-12-04 10:47

I\'ve seen := used in several code samples, but never with an accompanying explanation. It\'s not exactly possible to google its use without knowing the proper

10条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-04 11:11

    In the statically typed language Go := is initialization and assignment in one step. It is done to allow for interpreted-like creation of variables in a compiled language.

    // Creates and assigns
    answer := 42
    
    // Creates and assigns
    var answer = 42
    

提交回复
热议问题