In the second case, the value letters
goes into the delete_head
function and receives it in a place called t
(approximately t=letters
), and processes something under the name t
. We changed the value of t
within it, but none of the letters
were manipulated when delete_head
ended.
In the first case, t
contains letters
, so t
and letters
are connected to the same array object. So, if you apply the del
function del
called array object that t
points to, array object, the letters
are erased exactly as it was erased in t
. Because it's connected.
In fact, if you apply a code that changes the value of t
differently before you run delt[0]
in the code of delete_head
, the letters
will not be affected.
It would be helpful to study call by value
/ call by reference
that is accessed in other popular programming languages, and also to find out call by object reference
that is only spoken in Python. There are actually some problems with what I explained.
Call by object reference
I will add a link to what some people have organized.
https://item4.github.io/2015-07-18/Some-Ambiguousness-in-Python-Tutorial-Call-by-What/
http://hyunalee.tistory.com/43
© 2024 OneMinuteCode. All rights reserved.