The properties of slices
stay go In a slice of
When operating on different slices based on the same array , In essence, it operates in the same array space
If we are copying slices
Take the following statement for granted
var nums = []int{1, 2, 3}
copy :=numsIt may lead to bug Appearance
Let's take a look at this example

We had hoped for a copy copy Operate without changing nums Value
For this purpose, we have created a new variable copy
However, the result is 
The right thing to do is to use copy function

about copy Use of functions
We need to pay attention to the length of the parameter
If we use this copy

I thought I had finished the copy operation
But in fact
give the result as follows 
because co When declared, the default initialization is nil
because copy Characteristics of functions ,copy The operation will not be co Expand capacity
At the completion of the copy After the operation, it will still be nil
So if we think we have finished copy If the operation directly uses the slice, an exception will occur
For example, complete the exchange operation co[1], co[2] = co[2], co[1]
Will prompt for subscript out of bounds
panic: runtime error: index out of range [1] with length 0The correct way is to initialize it into slices of equal length

So we can get the right result




![Gee: explore the characteristics of precipitation change in the Yellow River Basin in the past 10 years [pixel by pixel analysis]](/img/ff/59956c2323567cc614458a2bccb642.jpg)

![Gee series: unit 8 time series analysis in Google Earth engine [time series]](/img/a6/648ff959af93c22dc8605215a90535.jpg)



![Gee: analyze the change of spatial centroid of remote sensing image [centroid acquisition analysis]](/img/25/a726643b96b6f7dbfee3782c4905d9.jpg)