2016-03-28 12 views

cevap

0

Bu, listelerin python içinde çalışmasının bir yolu olduğundan, işlevi listeye göndermez. Bu işlev, mevcut listenin bulunduğu bellekte yerini gönderir ve bu da

1

Bu, listelerin Python'da değiştirilebilmesi ve işlevinizin lst olarak değiştirilebilmesidir. Aslında, eksik return ifadesi ile ilgisi yoktur - tüm anlamı x = f(lst), xNone olacaktır.'u lst numaralı telefondan dönüştürmek istemiyorsanız, bir kopya gönderin.

lst = [1, 2, 3] 

def fn(lst): 
    print("in fn") 
    lst[1] = 10 

x = lst[::] # make a copy 
print("X before is:", x) 
fn(x) 
print("X after is:", x) 
print("Lst after calling fn with x but before using Lst is:", lst) 
fn(lst) 
print("Lst after is:", lst) 

Bu baskılar:

X before is: [1, 2, 3] 
in fn 
X after is: [1, 10, 3] 
Lst after calling fn with x but before using Lst is: [1, 2, 3] 
in fn 
Lst after is: [1, 10, 3] 
İlgili konular