go_playground/5-go-by-example/4-constants.go

27 lines
485 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package main
import (
"fmt"
"math"
)
// const declares a constant value.
const s string = "constant"
func main() {
fmt.Println(s)
// can appear anywhere a var statement can
const n = 500000000
// expressions perform arithmetic with arbitrary precision
const d = 3e20 / n
fmt.Println(d)
// numeric constants have no type until its given one
fmt.Println(int64(d))
// numbers can be given a type by using it in a context that requires one
fmt.Println(math.Sin(n))
}