Constant _golang in the Go language

Source: Internet
Author: User

A constant is the most basic element in a program and cannot be assigned again after it is defined. The constant types in the Go language are Boolean constants, integer constants, floating-point constants, Word constants, string constants, and complex constants.

Boolean Constants

Copy Code code as follows:

Const X = True
Fmt. Print (x)//Output True

Integer constants

Copy Code code as follows:

Const X = 20
Fmt. Print (x)//Output 20

Floating point numbers constant

Copy Code code as follows:

CONSTX = 0.618
Fmt. Print (x)//Output%f0.618

Word Constants Quantity

Copy Code code as follows:

Const x = ' a '
Fmt. Print (x)//Output 97

String constants

Copy Code code as follows:

Const x = "a"
Fmt. Print (x)/Output a

Plural constants

Copy Code code as follows:

Const X = 3 + 2i
Fmt. Print (x)//Output%v (3+2i)

A careful look at the boot will find that the output values of ' a ' and ' a ' are not the same, the single quote ' a ' denotes the character, and the double quote ' a ' denotes a string. In the Go "1′," 1″,1 is not the same value, this is the same as the C language. Interested children's boots can try out their own output try.

The above mentioned is the entire content of this article, I hope you can enjoy.

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.