Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to declare multivariable in Go language

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article is a detailed introduction to "How to declare Go language variables". The content is detailed, the steps are clear, and the details are properly handled. I hope this article "How to declare Go language variables" can help you solve your doubts. Let's go deeper and learn new knowledge together with the ideas of Xiaobian.

Multivariable declaration//Multiple variables of the same type, non-global variables var vname1, vname2, vname3 = v1, v2, v3var vname1, vname2, vname3 = v1, v2, v3 //Similar to python, no need to display declaration type, automatically infer vname1, vname2, vname3:= v1, v2, v3 //Variables appearing on the left side of:= should not have been declared, otherwise it will lead to compilation errors//This factorization keyword is generally used to declare global variables var (var) vname1 v_type1 vname2 v_type2 Examples

package main

var x, y int

var ( //This factorization keyword is generally used to declare global variables

a int

b bool

)

var c, d int = 1, 2

var e, f = 123, "hello"

//This undeclared format can only appear in the body of a function

//g, h := 123, "hello"

func main(){

g, h := 123, "hello"

println(x, y, a, b, c, d, e, f, g, h)

}

The implementation results of the above examples are:

0 0 0 false 1 2 123 hello 123 hello Read here, this article "How to declare Go language variables" article has been introduced, want to master the knowledge of this article also need to practice before you can understand, if you want to know more related content of the article, welcome to pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report