golang: slice slice

I have never understood the concept of slice slices very thoroughly. I didn't understand it when I learned python before, but I usually write a tool in python, and I didn't take this seriously to spend time solving it.

Recently, I encountered this problem again using go development, so I planned to completely clarify this concept, read a few articles, and recorded my understanding of slices:


There is a passage in this article, which I think is a simple and clear definition of slice:

 A slice is a data structure describing a contiguous section of an array stored separately from the slice variable itself. A slice is not an array. A slice describes a piece of an array.
A slice is a data structure that describes a contiguous piece of data stored elsewhere in an array. A slice is not an array. A slice describes a part of an array.
This reminds me of the concept of a view in a database, a view just defines a dataset, but it does not store data, the actual data is stored in other tables.


Guess you like