Exported names

설명

In Go, a name is exported if it begins with a capital letter. For example, Pizza is an exported name, as is Pi, which is exported from the math package.

pizza and pi do not start with a capital letter, so they are not exported.

When importing a package, you can refer only to its exported names. Any "unexported" names are not accessible from outside the package.

Run the code. Notice the error message.

To fix the error, rename math.pi to math.Pi and try it again.

package main

import (
	"fmt"
	"math"
)

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

에러메시지

에러메시지

Fuctions

package main

import "fmt"

func add(x int, y int) int {
	return x + y
}

func main() {
	fmt.Println(add(42, 13)) 
}

Functions continued

func add(a int, b int) //1
func add(a, b int) //2 

Multiple results

package main

import "fmt"

func swap(x, y string) (string, string) { return y, x }

func main() {
	a, b := swap("hello", "world")
	fmt.Println(a, b)
}