johanntagle icon

Go Multiple Variable Assignment

johanntagle | PRO | 11/12/19 02:24:48 AM UTC | 0 ⭐ | 14112 👁️ | Never ⏰ | []
Go |

510 B

|

None

|

0 👍

/

0 👎

package main
 
import (
    "fmt"
)
 
func main() {
    var d, e int
    d = 8
    e = 9
    fmt.Printf("These were declared in single line then assigned values later: %v %v\n", d,e)
 
    var (
        a=5
        b=6
        c=7
    )
    fmt.Printf("These were declared and assigned values using a multi-line group: %v %v %v\n", a,b,c)
    
    f := 10
    g := 11
    fmt.Printf("These were declared and assigned values using := : %v %v\n", f,g)
    
    var h, i = 12, 13
    fmt.Printf("These were declared and assigned values in single line: %v %v\n", h,i)  
}

Comments