ZeroRecursive Code | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

ZeroRecursive Code

Explanation of the code: https://code.sololearn.com/cYTdG0jtYWus/?ref=app I do not understand why only the first entry is updated to 0. By passing a[1:] recursively all the entries should be updated to 0. Any clarification about this behaviour will be helpful. Thanks !

7th Oct 2021, 6:11 AM
Simone Appella
Simone Appella - avatar
5 Answers
7th Oct 2021, 7:12 AM
Prabhas Koya
+ 2
First you updated a[0] = 0 then you passed a slice of the list as argument , it's same as passing [2,3,4] and it would do it's task for the given list([2,3,4]) and why would it change in a . Let me explain If you are sending a as argument and you changed something then that would change in a, but if you are sending some other list as argument then why would it change a.
7th Oct 2021, 7:02 AM
Prabhas Koya
+ 2
Thanks a lot Prabhas Koya . The test1 clarified any doubt. 👍
7th Oct 2021, 7:15 AM
Simone Appella
Simone Appella - avatar
0
Thanks Prabhas Koya for your reply. So do you mean that sending the slice of a list to the function is done by copy and not by reference ?
7th Oct 2021, 7:07 AM
Simone Appella
Simone Appella - avatar