Question: (a) Explain the difference between pass by reference and pass by value in one or two sentences. (b) Also explain what modifying in-place is. (c)

(a) Explain the difference between pass by reference and pass by value in one or two sentences. (b) Also explain what "modifying in-place" is. (c) Can you modify only the first line of the code below so that the output is (5, 5]? var = 5 def times Two-inPlace (a): a *= 2 times Two-inPlace (var) print (var) (d) Now do the same for the code below. Why doesn't it give the same result as before? (Hint: look closely at line 4.) How would you change the code (except for saying a t= 2) so that the same output as before will be printed? var = 5 # change this line with your answer to part (c) def times Two (a): a = a + 2 times Two (var) print (var) While functions in Python get their own local variables, loops and if/else do not. Here is an example, in which index is modified within the for loop and the global scope "knows" this. index = 1 for i in range (1,10): index = i print (index)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
