Nazmus Salehin Nazmus Salehin - 1 year ago 124
Python Question

Python (parameter passing)

When passing a list as an argument in function why the following list is not changed ?

def foo(*x):


The function is returning
[[3, 2, 1]]
. Not

Why is this happening ? Is this something to do with call by value ?

Answer Source

Why creating another function? You can just do this

>>> a = [3,2,1]
>>> sorted(a)
[1, 2, 3]

However if you want to create another function. You have to call it.

def foo(x):
    return y
a = [3,2,1]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download