package main
import "fmt"
func main() {
fmt.Println("Hello world")
}
package main
ํจํค์ง๋ฅผ ์ ์ธํ๋ ๋ถ๋ถ
ํจํค์ง์ ์ด๋ฆ์ด main์ผ๋ก ๋์ด์๋ค๋ฉด ํ๋ก๊ทธ๋จ ์คํ์ ์ํด ์กด์ฌํ๋ ํจํค์ง
ํด๋น ์ด๋ฆ์ด main์ด ์๋ ๋ค๋ฅธ์ด๋ฆ์ผ๋ก ๋์ด์๋ค๋ฉด ์คํ์ด ๋ ์ ์๊ณ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ฒ๋ผ ์ฌ์ฉํ๊ฒ ๋ค๋ ์๋ฏธ
c ์ธ์ด์ main๊ณผ ๋น์ทํ ๋งฅ๋ฝ
import "fmt"
fmt๋ผ๋ ๋ผ๋ ๋ชจ๋์ ๋ถ๋ฌ์จ๋ค.
python from์ด๋ c์ธ์ด์ include ์ ๋น์ทํ ๋งฅ๋ฝ
fmt.Println("Hello world")
hello world๋ผ๋ ๋ฌธ์๋ฅผ ์ถ๋ ฅํ๋ค.
fmt ์ถ๋ ฅ์๋ ํฌ๊ฒ 3๊ฐ์ง๊ฐ ์กด์ฌ
fmt.Print("hello world")
fmt.Println("hello world")
fmt.Printf("%s", "hello world")
print : ๋ฌธ์๋ฅผ ์ถ๋ ฅํ์ง๋ง newline์ด ๋์ค์ง์์
println : ๋ฌธ์๋ฅผ ์ถ๋ ฅํ๊ณ ๊ธฐ๋ณธ์ ์ผ๋ก newline ๋ด์ฅ
printf : ๋งค๊ฐ๋ณ์์ ์ถ๋ ฅํ ํ์์ ์ง์ ํด์ค ์ ์์
ํจ์ ๋ถ๋ฌ์ค๊ธฐ
package test
import "fmt"
func Test1() {
fmt.Println("test1")
}
func test2() {
fmt.Println("test2")
}
package main
import "github.com/k010103/learngo/test"
func main() {
test.Test1() // ๊ฐ๋ฅ O
test.test2() // ๋ถ๊ฐ๋ฅ X
}
ํจ์์ ๋งจ ์์ ๊ธ์๊ฐ ๋๋ฌธ์์ธ ๊ฒฝ์ฐ ํจ์๊ฐ public์ด ๋์ด ๋ค๋ฅธ ํ์ผ์์ ๋ถ๋ฌ์ฌ ์ ์๊ฒ๋๋ค.
fmt.Println() ๊ฒฝ์ฐ์๋ ๋งจ ์์ ๊ธ์๊ฐ ๋๋ฌธ์์ฌ์ ๋ถ๋ฌ์ฌ ์ ์๋ ํ์์ด๋ค.
'programming language > Go' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Go] go-tour _ flowcontrol (0) | 2021.09.25 |
---|---|
[Go] go-tour _ basics [17/17] (1) | 2021.09.23 |
[Go] go-tour _ basics [9/17] (2) | 2021.09.22 |
[Go] go-tour _ welcome (0) | 2021.09.21 |
go ์ค์น (2) | 2021.09.19 |