Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
vish21447yIn python , lists are passed by reference. So , if you add/update/delete elements inside the function using that pointer, it will reflect outside.
On the other hand, if you 'assign' a value inside the function, it won't update the pointer but instead it will create a new local variable. -
Basically, it's showing that array types are passed by reference, not value, at least how it works in the C language, and what I can remember from Python. "values" in this case, passed into the function 'f' as the variable 'v' is being modified in the function f at index 0 to have the value 44. That's why when the output is shown, v[0] is 44. Sorry if this is kind of crap, doing it on my phone, and can't see the code...
And right, my Python is rusty AF. Array can be replaced by list. Updated after reading vish's post. -
sSam14837y@Lahsen2016 thought u were talking about & operator in function declaration. Still when you use & operator you get the address of the variable so you pass the value of the pointer, reference, but for me it still doesn't count as pass by reference.
-
sSam14837yYes, I understand what you mean, but what I mean is that you pass the VALUE of the pointer, you don't pass the variable by reference.
Related Rants
I saw this quiz. This is Python, right?
I ran this and got '3 44' although I'm not completely sure why the 44. I can see the obvious correlation between 'values [0]' and 'v[0]'. Aside from that I'm not sure.
Can anyone explain this to me?
question
python
quiz
python 3