Nov-18-2019, 04:42 AM
Hello,
I would like to know if python passed certain data types by value, and other data types by reference.
Here is an example:
Thank you
I would like to know if python passed certain data types by value, and other data types by reference.
Here is an example:
def multiply(myArg): myArg = myArg * 2 return myArg y = 5 multiply(y) print y # Result is 5, so the variable Y was passed by value? def appendToList(myList): myList.append("luululu") someList = list() appendToList(someList) print someList # Result: ['luululu'], so it was passed by reference?As you can see the variable y was not modified, whereas the list was modified. So are numeric types passed by value and lists, tuples and other objects passed by reference?
Thank you