Go程序是通过package来组织的,package名称为main时,可以包含main函数,并且一个可执行程序有且仅有一个mian包。
通过import来导入用到的包,const定义常量,函数体外用var进行全局变量声明和赋值。
type关键字来进行结构或接口的声明。
//包名
package main
//导入用到的包,别名格式为import abc "fmt" ,省略格式为import . "fmt" ,二者选一 import "fmt"
//定义常量 const PI = 3.14
//定义全局变量 var name = "test"
//一般类型的声明 type a int
//结构声明 type b struct{}
//接口声明 type c interface{}
//主入口别名调用:abc.Println("Hello world!"),省略调用:Println("Hello world!") func main(){ fmt.Println("Hello world!") }
Go语言中,使用大小写来决定是否可以被外部包所调用,函数名为小写即为private,大写即为public.
浙公网安备 33010602011771号