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

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. DB天气app冲刺第七天

    今天估计得分应该是最差的了. 今天因为完全没准备所以在界面UI上面根本就是相当于没弄.结果今天的各组报告里自己做得很不好.不过好在只是项目的中间期,不碍大事. 今天也完成了任务.可以说超额了也.因为吃 ...

  2. hdu 3333 Turing Tree 图灵树(线段树 + 二分离散)

    http://acm.hdu.edu.cn/showproblem.php?pid=3333 Turing Tree Time Limit: 6000/3000 MS (Java/Others)    ...

  3. BZOJ 3953 Self-Assembly 解题报告

    首先,我们可以先考虑一个暴力一点的算法: 对于任意两个分子,如果它们能以至少一种进行匹配,那么我们就在这两个分子之间连一条边. 然后如果我们能找到一个环,就说明是 unbounded,否则就是 bou ...

  4. 解决win8 plsql无法登录

    今天安装完oracle客户端,然后打开 plsql 之后,就一个提示框,提示没有登录,后来解决方法如下: 在plsql的图标上点右键,以管理员身份运行,即可! 如果不想一直点右键执行,就图标上点右键- ...

  5. 练习--LINUX进程间通信之信号SIGNAL

    同样的,信号也不要太迷信可靠信号及不及靠信号,实时或非实时信号. 但必须要了解这些信号之间的差异,函数升级及参数,才能熟练运用. ~~~~~~~~~~~~~~~~ 信号本质 信号是在软件层次上对中断机 ...

  6. Tomcat 6 支持 NIO -- Tomcat的四种基于HTTP协议的Connector性能比较(转载)

    Tomcat从5.5版本开始,支持以下四种Connector的配置分别为: <Connector port="8081" protocol="org.apache. ...

  7. SPRING IN ACTION 第4版笔记-第六章RENDERING WEB VIEWS-005- 使用ApacheTiles(TilesConfigurer、TilesViewResolver、<put-attribute>、<t:insertAttribute>)

    一. 1.定义TilesConfigurer.TilesViewResolver的bean 注意有tiles2和tiles3,这里使用tiles3 (1)java形式 package spittr.w ...

  8. SPRING IN ACTION 第4版笔记-第三章ADVANCING WIRING-006-给bean运行时注入值(Environment,Property文件)

    一. 直观的给bean注入值如下: @Bean public CompactDisc sgtPeppers() { return new BlankDisc( "Sgt. Pepper's ...

  9. ANDROID_MARS学习笔记_S01原始版_009_SQLite

    一.代码1.xml(1)activity_main.xml <?xml version="1.0" encoding="utf-8"?> <L ...

  10. 忘记commit的一次教训

    由于业务需求,已经上线的系统新增加了一些需求,其中一个需求是,从一个SQLSERVER数据库导入数据到生产的ORCLE数据库, 由于我的失误导致系统上线后 生产的Oracle数据没有导入成功,但是在本 ...