In Golang, there are several ways to declare variables:
-
Using the
varkeyword:govar a int var b string -
Declare and initialize variables:
govar a int = 10 var b string = "Hello" -
Short variable declaration (only usable within functions):
goa := 10 b := "Hello" -
Declare multiple variables:
govar a, b, c int var d, e string = "Hello", "World" f, g := 123, "Hello"
When choosing a declaration method, consider the use case and code readability.