New course! Every coder should learn Generative AI!
Try a free lesson0
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 !
5 Answers
+ 3
https://code.sololearn.com/c66whNN3Q3AJ/?ref=app
You can do like this
+ 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.
+ 2
Thanks a lot Prabhas Koya . The test1 clarified any doubt. 👍
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 ?