Home
Sign Up
Sign In
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member
Sign In
The Go Programming Language
›
http://golang.org/
›
Go Playground
Go Projects
›
Revel Web Framework
Advertisement
V2EX
›
Go 编程语言
请教一下, golang 里 arr[len(arr):]这个切片应该如何理解?
goofool
·
Feb 19, 2019
· 3090 views
This topic created in 2626 days ago, the information mentioned may be changed or developed.
例如
arr := []int{1, 2}
fmt.Println(arr[2:])
按我理解,这个 arr[2:]应该报错吧,但实际并没有而且返回了[]int
只有到 arr[3:]才开始报错
Supplement 1 ·
Feb 19, 2019
https://golang.org/ref/spec#Slice_expressions
arr
int
Golang
fmt
2 replies
•
2019-02-19 11:24:18 +08:00
1
SuperMild
Feb 19, 2019
查了官方 Spec,
0 <= low <= high <= len(a)
因此,low 和 high 都可以等于 len(arr)
2
per
Feb 19, 2019
https://stackoverflow.com/questions/45299185/slice-start-position-greater-than-length-of-the-string
About
·
Help
·
Advertise
·
Blog
·
API
·
FAQ
·
Solana
·
3679 Online
Highest 6679
·
Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 32ms ·
UTC 04:38
·
PVG 12:38
·
LAX 21:38
·
JFK 00:38
♥ Do have faith in what you're doing.
❯