This is a creation in Article, where the information may have evolved or changed.
Initialization
Slices can be initialized by an array, or by using the built-in function make (). Len=cap at initialization time, if the capacity cap is not sufficient when appending elements to see sample code at twice times the size of Len, run the sample code online
S: =[] int {A-i}
The direct initialization of the slice, [] means the slice type, and the {-i} initialization value is in turn a. Its cap=len=3
S: = arr[:]
Initializes the slice S, which is a reference to the array arr
S: = Arr[startindex:endindex]
Create an element in Arr from subscript startindex to endIndex-1 as a new slice
S: = Arr[startindex:]
The default endindex will represent the last element to arr
S: = Arr[:endindex]
The default startindex will represent the start of the first element in arr
S1: = S[startindex:endindex]
Initializing slices by slicing s S1
S: =make ([]int,len,cap)
Initialize slice s,[]int with built-in function make () to identify slices whose element type is int
Assignment and use
A slice is a reference type and you need to be aware of its actions when you use it. To view the sample code, run the sample code slice online via the built-in function append (slice []type,elems ... Type) appends an element, Elems can be a row of type data, or it can be slice because one of the elements is appended, so if you append one slice to another slice you need to bring "...", This means that the elements in the slice are appended to the other slice in turn. In addition, the subscript cannot exceed the Len size when the element is accessed by subscript, as if the subscript of the array cannot exceed the Len range.
S: =append (s,1,2,3,4)
S: =append (S,s1 ...)