I was told that the python function is passing by reference, here is an example
def append_element(some_list, element):
some_list.append(element)
data = [3, 1, 2]
append_element(data, 4)
print(data)
[3,1,2,4]
So the original data
has changed. What makes me feel confused is
y = sorted(data)
print(y)
[1,2,3,4]
print(data)
[3,1,2,4]
If python function is indeed passing by reference, then why after this function call sorted()
, the data
did not change?