I can change an element of a list through the following code:
def myFunction(x):
x[0] = 2
myList = [4,5,6]
myFunction(myList)
print(myList) # ==> outputs [2,5,6] (myList[0] is changed to '2' through the function).
But I don't understand why I cannot change a variable using the same code:
def myFunction(x):
x = 2
myNumber = 6
myFunction(myNumber)
print(myNumber) # ==> outputs 6 (myNumber is not changed to '2' through the function).