U
U
uvelichitel2019-08-02 07:20:47
go
uvelichitel, 2019-08-02 07:20:47

Why can foo[len(foo):]?

foo := [5]int{0, 1, 2, 3, 4}
fmt.Println(foo[:5]) //так можно
fmt.Println(foo[5:]) //и так
fmt.Println(foo[5])  //так нет. Почему?
//Где это документировано? Как это понимать

https://play.golang.org/p/J55-p3hW_tB

Answer the question

In order to leave comments, you need to log in

8 answer(s)
I
iveronanomi, 2019-08-06
@iveronanomi

You are wrong about the lack of documentation on this topic

a[2:]  // same as a[2 : len(a)]
a[:3]  // same as a[0 : 3]
a[:]   // same as a[0 : len(a)]

A
Alexey〒., 2019-09-02
@axifive

Because this is a call to a non-existent 5th element in the array. Addressing starts at index 0 and the element with index 4 is the last one in it. The first border is included in the slice; the latter is not included, so we write - this is an empty slice, you can also get it like this: or like this:foo[5]
fmt.Println(foo[1:1])

L
lavezzi1, 2017-12-01
@lavezzi1

https://dribbble.com/

L
Lumore, 2017-12-01
@Lumore

A selection of works from popular sources: flatun.com

A
Anastasia Mr, 2017-12-03
@nicepotato

behanes, dribble

O
oh, 2017-12-08
well @AnneSmith

here are the coolest
https://www.awwwards.com/

P
Philip Gavrilov, 2018-01-23
@Filgavrilov

Be inspired by everything, but not by other people's interfaces, because it will be just copying. This is a dead end development.

M
Michael, 2018-10-09
@efreytor

develop a sense of taste, at least pay attention to all the graphics on the streets of your city

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question