Go by Example: Constants
The Go language supports constants of character, String, Boolean, and numeric type variables.
Package mainimport "fmt" import "math" // use the keyword const to declare a constant const s string = "constant" func main () {fmt. println (s) // Where any var declaration can appear, you can use the const statement const n = 500000000 // a constant expression to execute any precision calculation. Const d = 3e20/n fmt. println (d) // a numeric constant has no type unless the corresponding type is given in the statement, for example, forced type conversion fmt. println (int64 (d) // according to the context of the statement, a numerical constant is assigned the corresponding type. For example, in variable declaration or function call // For example, if the function math. Sin () requires a float64 value, n is treated as a float64 value. Fmt. Println (math. Sin (n ))}Output
$ Go run constant. go constant6e + 11600000000000-0.28470407323754404
Next example:.
Original ENGLISH