Go (a) variable

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.
Package Mainimport ("FMT") Func main () {varAinta=1    varA1stringA1="my is A1"B:=2B1:="My is B1"FMT. Println (A,"^^^^", A1) Fmt. Println (b,"^^^^", B1)}

[' Go run Test.go ' | done:208.870174ms]
1 ^^ ^^ my is A1
2 ^^ ^^ My is B1

The next piece is interesting, with a python list of shadows, but the go language is called a "byte array"

Package Mainimport (    "fmt") Func main () {    A:'my is b"    B:= []byte(a)    FMT. Println (string(b[0))}

[' Go run Test.go ' | done:190.573207ms]
M

Package Mainimport (    "fmt") Func main () {    A:'my is b" +        "  test"    B:= ' My        name           is '    fmt. Println (a)    FMT. Println (b)}

[' Go run Test.go ' | done:197.232301ms]
My is B test
My
Name
Is

var is the one that declares global variables and assigns values.

The definition of a const constant,

Type declaration of a generic type

Package Mainimport (    "fmt") Func main () {    var  (         " Wang " Age)fmt.       Print ("hello""Age was:", Age)}

[' Go run Hello.go ' | done:201.697722ms]
Hellowangage Is:12

Type lingzhii:

When a variable is declared as a default value after some type,

Typically, the value type is 0

BOOL is False

String is empty

Package Mainimport (    "fmt") Func main () {    varint     varstring    varbool    FMT. Println (a)    FMT. Println (b)    FMT. Println (c)}

[' Go run Test1.go ' | done:215.061592ms]
0

False

 

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.