Go language Variable definition usage instance _golang

Source: Internet
Author: User

The examples in this article describe the use of Go language variable definitions. Share to everyone for your reference. Specifically as follows:

The VAR statement defines a list of variables, the same as the function's argument list, and the type is in the back.

Copy Code code as follows:
Package Main
Import "FMT"
var x, y, Z int
var c, Python, Java bool
Func Main () {
Fmt. Println (x, Y, Z, c, Python, Java)
}

A variable definition can contain an initial value, and each variable corresponds to one.

If the initialization is using an expression, you can omit the type, and the variable obtains the type from the initial value.

Copy Code code as follows:
Package Main
Import "FMT"
var x, y, Z int = 1, 2, 3
var c, Python, Java = True, False, "no!"
Func Main () {
Fmt. Println (x, Y, Z, c, Python, Java)
}

In a function,: = A concise assignment statement can be used instead of the VAR definition where it is explicitly typed.

(: = struct cannot be used outside a function, each block of syntax outside a function must start with a keyword.) )

Copy Code code as follows:
Package Main
Import "FMT"
Func Main () {
var x, y, Z int = 1, 2, 3
C, Python, Java: = True, False, "no!"
Fmt. Println (x, Y, Z, c, Python, Java)
}

I hope this article will help you with your go language program.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.