Declare slice or make slice?
问题 In Golang, what is the difference between var s []int and s := make([]int, 0) ? I find that both works, but which one is better? 回答1: In addition to fabriziom's answer, you can see more examples at "Go Slices: usage and internals", where a use for []int is mentioned: Since the zero value of a slice ( nil ) acts like a zero-length slice , you can declare a slice variable and then append to it in a loop: // Filter returns a new slice holding only // the elements of s that satisfy f() func