Go variables hold typed values that can feed later expressions.

Variables

variables.go
package main

import "fmt"

func main() {
	var unitPrice = 
	quantity := 3
	total := unitPrice * quantity

	fmt.Println("unit=", unitPrice)
	fmt.Println("total=", total)
}
package main

import "fmt"

func main() {
	var unitPrice = 
	quantity := 3
	total := unitPrice * quantity

	fmt.Println("unit=", unitPrice)
	fmt.Println("total=", total)
}
package main

import "fmt"

func main() {
	var unitPrice = 
	quantity := 3
	total := unitPrice * quantity

	fmt.Println("unit=", unitPrice)
	fmt.Println("total=", total)
}
variable `var` declares a variable. Go infers the type from the value when no explicit type is written.