“Go” Language Tutorial-5(Exported Names)

Posted: June 26, 2012 in Go, Language
Tags: , , , , ,

EXPORTED NAMES

 

After importing a package, you can refer to the names it exports.

In Go, a name is exported if it begins with a capital letter.

Foo is an exported name, as is FOO. The name foo is not exported.

Run the code. Then rename math.pi to math.Pi and try it again.

Example :

package main

import (
“fmt”
“math”
)

func main() {
fmt.Println(math.pi)
}

output:

prog.go:9: cannot refer to unexported name math.pi
prog.go:9: undefined: math.pi

after renaming math.pi to math.Pi

package main

import (
“fmt”
“math”
)

func main() {
fmt.Println(math.Pi)
}

output:

3.141592653589793

Leave a comment