目录


新建一个文件 example.go

// 声明该文件所在包,如果是主程序就是main,不是主程序就写包名
package main
// 导入库,fmt用来处理标准输入输出
import "fmt"

// main函数就是整个函数的入库,main函数所在的报名也必须为‘main’
func main() {
	// 调用fmt的Println方法,在屏幕输出信息
	fmt.Println("hello,world")
	fmt.Println("this is my first Go!")
}

运行结果

[root@localhost go_lianxi]# go run example.go 
hello,world
this is my first Go!

Go语法规则:

package main
声明了 main.go 所在的包,Go 语言中使用包来组织代码。一般一个文件夹即一个包,包内可以暴露类型
或方法供其他包使用。