我想知道为什么第二个fmt.Println中的"s [1:]"没有抛出索引超出范围错误?指数1明显超出范围
package main
import "fmt"
func main() {
s := "J"
//fmt.Println(s[1]) // This results in a runtime error: index out of range
fmt.Println(s[1:]) // Why does this work? Index value 1 is clearly out of range, but the statement prints an empty string
}
Run Code Online (Sandbox Code Playgroud) go ×1