NEWBIE: lists as function arguments

Batista, Facundo FBatista at uniFON.com.ar
Fri Nov 7 13:43:07 EST 2003


Joe Poniatowski wrote:

#- >>> ls = []
#- >>> def f1(l2=[]):
#- ...     l2 = ['word1','word2']
#- ...     print l2
#- ...
#- >>> f1(ls)
#- ['word1', 'word2']
#- >>> ls
#- []
#- >>>

When you pass ls to f1, you're pointing l2 to ls.

Then, you point l2 to ['word1','word2']. But ls is still pointing to [] (you
never changed that).

.	Facundo





More information about the Python-list mailing list