+ 3
Can anyone explain this as simply as possible ?
3 Réponses
+ 5
A function assigns a new value to L list inside it (not the one in the global scope) and simply returns it -- assigns the ultimate value to the function itself, which you print out.
B function, on the other hand, assumes the argument as reference and alters its first element, so the list L is in fact changed.
+ 2
What is happening is 2 functions have been set, one to make the variable equal to the character A and the other to make the variable a list and set its first index as the character B.
The first line sends the variable L through the first function. This will set L to A and return its value (therefore printing A).
The second line will print the base value of L, before it went through any of the functions.
The next line runs L through the second function. While in the function, the first index of L will be set to B, and it will return the entire list (except it will just be B)
The final line will once again print the value of L, but because its first index was set to B instead of 1, it will print out ["B"].
Hope this helped!
+ 1
Thank you !