It seems. I didn't know. Or rather, I didn't really care.
I thought that int was treated specially and passed by value from the viewpoint of behavior, but it was passed by reference for "all".
Below is an experiment with ipython.
In [27]: i = 1
In [28]: id(i)
Out[28]: 140513240953112
In [29]: def func(a):
....: print a, id(a)
....: a += 1
....: print a, id(a)
....: return a
....:
In [30]: b = func(i)
1 140513240953112 <-Same place so far(id)Referencing
2 140513240953088 <-Another place here(id)Copied to
In [31]: id(b)
Out[31]: 140513240953088
Another example
In [32]: i = 1
In [33]: id(i)
Out[33]: 140513240953112
In [34]: def func(a):
....: print a, id(a)
....: return a
....:
In [35]: b = func(i)
1 140513240953112
In [36]: id(b)
Out[36]: 140513240953112 <-Again the same place as i(id)Referencing
In [37]: b
Out[37]: 1 <-Reading from the same location as i
In [38]: b += 2 <-Another place here(id)Copied to
In [39]: id(b)
Out[39]: 140513240953064 <-You see, it's strange
Hey. That's what it is.
-[Python] Common sense, right? An introduction to arguments to avoid being told
When I tried hard to tune with python, the reference cost via the Array index became a bottleneck until the end. Well, if you are familiar with python, you may still be able to do it, but it is faster to change the language than trying hard with python, so it is necessary to dive into the deep part of python. There is no. I'm interested.
As an option to change the language, I easily go to C / C ++ now, but I think it is necessary to make the Go language more responsive. I'm thinking. really.
end.
Recommended Posts