Home
Sign Up
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
· 3528 views
This topic created in 2831 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
SuperMild
Feb 19, 2019
1
查了官方 Spec,
0 <= low <= high <= len(a)
因此,low 和 high 都可以等于 len(arr)
per
Feb 19, 2019
2
https://stackoverflow.com/questions/45299185/slice-start-position-greater-than-length-of-the-string
About
·
Help
·
Advertise
·
Blog
·
API
·
FAQ
·
Privacy
·
Solana
·
1994 Online
Highest 6679
·
Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 27ms ·
UTC 01:28
·
PVG 09:28
·
LAX 17:28
·
JFK 20:28
♥ Do have faith in what you're doing.
❯