This is a creation in Article, where the information may have evolved or changed.
The go language supports constants for characters, strings, booleans, and numeric type variables.
Package Mainimport "FMT" import "math"//Use keyword const to declare a constant const s string = "constant" Func main () { fmt. PRINTLN (s)//either a var declaration can occur anywhere you can use the const declaration CONST n = 500000000//constant expression can perform calculations of arbitrary precision. Const D = 3e20/n fmt. Println (d)//A numeric constant does not have a type unless the corresponding type is given in the statement, such as converting FMT with coercion type . PRINTLN (Int64 (d))//depending on the context of the statement, a numeric constant is given the appropriate type. For example: in a variable declaration or function call//For example, here the function of math. Sin () requires a float64 value, and N is manipulated as a float64 value. Fmt. Println (Math. Sin (n))}
Output
$ go Run constant.go constant6e+11600000000000-0.28470407323754404
Next example: For.
English original