In go :
A is an array
B:=A[:]
or
B:=A
then B is a copy of A
B:=A[2:5]
then B is a pointer to A[2] (I mean when an element in B is modified, the corresponding element in A is also modified.)
in python, its just the opposite way. why does go think its way is better?
ps:
what is the difference between B:=A[0:] and B:=A[0:6] when A has seven elements? in the latter case, I found A modified when B is modified, while in the former case, A is not.
my go version is 1.02 for windows.
thanks and regards,
dean
In go :
A is an array
B:=A[:]
or
B:=A
then B is a copy of A
B:=A[2:5]
then B is a pointer to A[2] (I mean when an element in B is modified, the corresponding element in A is also modified.)in python, its just the opposite way. why does go think its way is better?
ps:
what is the difference between B:=A[0:] and B:=A[0:6] when A has seven elements? in the latter case, I found A modified when B is modified, while in the former case, A is not.
then B is a copy of A
what is the difference between B:=A[0:] and B:=A[0:6] when A has seven elements? in the latter case, I found A modified when B is modified, while in the former case, A is not.
Your experiments are not working. Nothing you did ever copied any arrays.
import(
"fmt"
)
func main(){
var A=[]int{1,2,3,4,5}//or var A=[5]int{1,2,3,4,5}
B:=A// or B:=A[0:] or B:=A[:]
B[1]=6
fmt.Println(A)
}