导入包
关键字 import
语法规则
- 单个导入
import "包名"
- 多个导入
import (
"包名1"
"包名2"
"包名3"
...
)
- 导入包使用别名
import 别名 "包名"
例子
- 导入
打印包
package main
import "fmt"
func main() {
fmt.Println("hello world")
}
- 导入
打印包
和字符串包
package main
import (
"fmt"
"strings"
)
func main() {
fmt.Println("hello world")
fmt.Println(strings.Repeat("hello ", 3)) // 字符串重复
}
// $ go run main.go
// 输出如下
/**
hello world
hello hello hello
*/
- 导入包使用别名
package main
import (
"fmt"
myStr "strings"
)
func main() {
fmt.Println(myStr.Repeat("hello ", 3))
}
// $ go run main.go
// 输出如下
/**
hello hello hello
*/
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。