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

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{, , , , , }
fmt.Println("p ==", p)
fmt.Println("p[1:4] ==", p[:]) //missing low index implies 0
fmt.Println("p[:3] ==", p[:]) // missing high index implies len(s)
fmt.Println("p[4:] ==", p[:])
}
package main 

import "fmt"

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

A Tour of Go Slicing slices的更多相关文章

  1. A Tour of Go Nil slices

    The zero value of a slice is nil. A nil slice has a length and capacity of 0. (To learn more about s ...

  2. A Tour of Go Making slices

    Slices are created with the make function. It works by allocating a zeroed array and returning a sli ...

  3. A Tour of Go Exercise: Slices

    Implement Pic. It should return a slice of length dy, each element of which is a slice of dx 8-bit u ...

  4. A Tour of Go Slices

    A slice points to an array of values and also includes a length. []T is a slice with elements of typ ...

  5. exercise.tour.go google的go官方教程答案

    /* Exercise: Loops and Functions #43 */ package main import ( "fmt" "math" ) fun ...

  6. Go Slices: usage and internals

    Introduction Go's slice type provides a convenient and efficient means of working with sequences of ...

  7. go官网教程A Tour of Go

    http://tour.golang.org/#1 中文版:http://go-tour-cn.appsp0t.com/#4 package main import ( "fmt" ...

  8. Python学习--字符串slicing

    Found this great table at http://wiki.python.org/moin/MovingToPythonFromOtherLanguages Python indexe ...

  9. 17 Go Slices: usage and internals GO语言切片: 使用和内部

    Go Slices: usage and internals  GO语言切片: 使用和内部 5 January 2011 Introduction Go's slice type provides a ...

随机推荐

  1. C#操作mongodb数据库

    1.下载驱动: 如下图:选择c#解决方案,右键,点击 “管理NuGet程序包(N)...” 在弹出的对话框中,输入MongoDB.Driver,进行搜索,然后选择安装. 2.引用命名空间: using ...

  2. UPUPW PHP环境集成包

    UPUPW PHP环境集成包 http://www.upupw.net/

  3. [jobdu]数组中出现次数超过一半的数字

    找到以后要再扫一遍确认. http://zhedahht.blog.163.com/blog/static/25411174201085114733349/ #include <iostream ...

  4. 《ArcGIS Engine+C#实例开发教程》第二讲 菜单的添加及其实现

    原文:<ArcGIS Engine+C#实例开发教程>第二讲 菜单的添加及其实现 摘要:在上一讲中,我们实现了应用程序基本框架,其中有个小错误,在此先跟大家说明下.在“属性”选项卡中,我们 ...

  5. money 和 smallmoney

    代表货币或货币值的数据类型. 数据类型 范围 存储 money -922,337,203,685,477.5808 到 922,337,203,685,477.5807 8 字节 smallmoney ...

  6. Dagger 2: Step To Step

    文/iamwent(简书作者)原文链接:http://www.jianshu.com/p/7505d92d7748著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”. 假设你已经了解 依赖注 ...

  7. 2015年NEUACM一月月赛题解

    A Money , money 时间限制: 1 Sec  内存限制: 128 MB 提交: 15  解决: 14 题目描述 Small K seen recently stock market rea ...

  8. 白书P61 - 点集配对问题

    白书P61 - 点集配对问题 状压DP #include <iostream> #include <cstdio> #include <cstring> using ...

  9. 用PowerShell批量部署wsp包

    转:http://www.xuebuyuan.com/168337.html 提供wsp部署的参数: $wsppath:wsp文件所在的路径,如"c:\" $wspnames:路径 ...

  10. windows下rundll32介绍

    最近看书介绍rundll32可以加载dll文件并执行其中导出函数,在MSDN中我们可以看到绍http://support.microsoft.com/kb/164787/zh-cn rundll32调 ...