博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
A Tour of Go Slicing slices
阅读量:6985 次
发布时间:2019-06-27

本文共 933 字,大约阅读时间需要 3 分钟。

---恢复内容开始---

Slices can be re-sliced, creating a new slice value that points to the same array.

The expression

s[lo:hi]

evaluates to a slice of the elements from lo through hi-1, inclusive. Thus

s[lo:lo]

is empty and

s[lo:lo+1]

has one element.

package main import "fmt"func main() {    p := []int{
2, 3, 5, 7, 11, 13} fmt.Println("p ==", p) fmt.Println("p[1:4] ==", p[1:4]) //missing low index implies 0 fmt.Println("p[:3] ==", p[:3]) // missing high index implies len(s) fmt.Println("p[4:] ==", p[4:])}

 

package main import "fmt"func main() {    p := []int{
2, 3, 5, 7, 11, 13} fmt.Println("p ==", p) fmt.Println("p[1:4] ==", p[1:4]) //missing low index implies 0 fmt.Println("p[:3] ==", p[:3]) // missing high index implies len(s) fmt.Println("p[4:] ==", p[4:]) var a [2]string a[0] = "Hello" a[1] = "World" fmt.Println(a[0:1])}

 

转载于:https://www.cnblogs.com/ghgyj/p/4053317.html

你可能感兴趣的文章
西门子计划发布全新平台,支持其全球增材制造愿景
查看>>
量子计算机秀肌肉:首次成功模拟高能物理实验
查看>>
10034 - Freckles 克鲁斯克尔最小生成树!~
查看>>
vmware vsphere client vclient viclient 下载地址
查看>>
Java的内存模型
查看>>
安装memcached
查看>>
Windows计算机重置TCP / IP
查看>>
SinoBBD亮相全球云计算大会 彰显一体化云力量
查看>>
AndroidStudio调用so文件
查看>>
Hadoop常用下载地址
查看>>
Oracle 分区表的新增、修改、删除、合并。普通表转分区表方法
查看>>
根据MAC地址查询网卡厂商
查看>>
菜鸟末端配送机器人年内投入商用!下一步要研发卡车
查看>>
[前端]JS时钟实例
查看>>
阿里云CentOS搭建Linux系统
查看>>
39、BGP配置实验之基础配置
查看>>
oj1330Nearest Common Ancestors 1470 Closest Common Ancestors(LCA算法)
查看>>
数据库之触发器
查看>>
14种网站最差的用户体验
查看>>
菜鸟学Linux 第017篇笔记 sed命令的使用
查看>>