go 包变量函数

包, 变量, 函数

package

包 是 go 中代码 组织的 单元, 用来 被 其他程序 引入.

go 复制代码
package main

import (
	"fmt"
	"math/rand"
)

func main() {
	fmt.Println("my favorite number is ", rand.Intn(10))
}

为了 简洁, 包 可以 直接 被 尾缀 引用,

比如 math/rand 可以 直接 用 rand 代表

代码 应该 从 main 包 中 开始

导入 包

bash 复制代码
import (
	"fmt"
	"math"
)
bash 复制代码
import "fmt"
import "math"
相关推荐
软件黑马王子34 分钟前
C#初级教程(4)——流程控制:从基础到实践
开发语言·c#
闲猫37 分钟前
go orm GORM
开发语言·后端·golang
丁卯4041 小时前
Go语言中使用viper绑定结构体和yaml文件信息时,标签的使用
服务器·后端·golang
李白同学2 小时前
【C语言】结构体内存对齐问题
c语言·开发语言
黑子哥呢?3 小时前
安装Bash completion解决tab不能补全问题
开发语言·bash
青龙小码农3 小时前
yum报错:bash: /usr/bin/yum: /usr/bin/python: 坏的解释器:没有那个文件或目录
开发语言·python·bash·liunx
大数据追光猿4 小时前
Python应用算法之贪心算法理解和实践
大数据·开发语言·人工智能·python·深度学习·算法·贪心算法
彳卸风4 小时前
Unable to parse timestamp value: “20250220135445“, expected format is
开发语言
bing_1585 小时前
简单工厂模式 (Simple Factory Pattern) 在Spring Boot 中的应用
spring boot·后端·简单工厂模式
dorabighead5 小时前
JavaScript 高级程序设计 读书笔记(第三章)
开发语言·javascript·ecmascript