+ 1
Why i get output like this? In the last line of code i just print(f) but the output is different from the input variable.
def myfunc(v) v*=3 print(v) v=3 myfunc(v) print(v) f=[1,2] myfunc(f) print(f) output is: 27 3 [1,2,1,2,1,2] [1,2,1,2,1,2] đhow i get this kind of output
4 RĂ©ponses
+ 1
Arrays are object, so you pass in argument the address of the object. Then, the function modify the object, that's why you get a different output.
+ 1
Excuse me if you don't understand, I'm a bad teacher! đą
+ 1
thank you so much Théophile
+ 1
You're welcome!