乐闻世界logo
搜索文章和话题

How to Declare Variables in Golang?

2月7日 11:37

In Golang, there are several ways to declare variables:

  1. Using the var keyword:

    go
    var a int var b string
  2. Declare and initialize variables:

    go
    var a int = 10 var b string = "Hello"
  3. Short variable declaration (only usable within functions):

    go
    a := 10 b := "Hello"
  4. Declare multiple variables:

    go
    var 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.

标签:Golang