본문 바로가기
Programming/Golang

패키지(package)

by 기적 2019. 12. 11.

 

위 설명과 같이 하나의 패키지명을 작성해준다.

테스트를 하기 위해 다음과 같이 작성하였다(A Tour of go 사이트 참조)

package main

import (
	"fmt"
	"math"
)
func main() {
	fmt.Println("Happy", math.Pi, "Day")
}

 

결과

패키지 이름은 filepath.go라고 작성하였다.

여기서 보면 import에서 math를 추가하여 math.Pi의 값을 출력하였다. 

출력할때 기존의 c언어처럼 %d라고 쓰지 않아도 출력되는 것을 볼 수 있다. 

go 언어가 배우기 쉽다고 그러던데 이런 면에서 크게 실수 할 일이 없을거 같다고 생각이 든다.

import한 fmt나 math에 어떤것이 포함되어 있는지 확인해 봐야 할 것 같다.

참고할 수 있는 사이트는

https://golang.org/pkg/fmt/

 

 

fmt - The Go Programming Language

These examples demonstrate the basics of printing using a format string. Printf, Sprintf, and Fprintf all take a format string that specifies how to format the subsequent arguments. For example, %d (we call that a 'verb') says to print the corresponding ar

golang.org

https://golang.org/pkg/math/

 

math - The Go Programming Language

Package math

URL의 맨 뒤에 부분만 변경하면 찾고자 하는 패키지를 찾을 수 있다.

이상! 다음으로~

댓글