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.