Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1
This is different in different languages. In Python, whatever you pass is always just a reference to the object, and the object itself decides, if you can change it or not. So basically def f(x) means: 'When we call this function later, pass one object of whatever sort and call it by the name x.' So if x is a number, you can't change it, if it's a list, you can. That's what 'mutable' and 'immutable' types are about. You can then write x = whatever in your function. But this doesn't mean that you are changing the object referred to by x - you're just stripping off the *name* x, and then you stick it to a completely different object.
22nd Feb 2020, 5:20 PM
HonFu
HonFu - avatar