arg-passing style question

Irmen de Jong irmen at -NOSPAM-REMOVETHIS-xs4all.nl
Sat Apr 19 22:21:13 CEST 2003


Guy Middleton wrote:
> I want to pass two values to a function that expects a single argument.
> 
> So, I could wrap them in either a list or a tuple.  Is either way preferred
> over the other?
> 
> 
> queue = Queue.Queue()
> a = "foo"
> b = {"key": "value"}
> queue.put((a,b))	# this works
> queue.put([a,b])	# this works too


This depends on what you do with the argument.
Keep in mind that a tuple is immutable.
A list object is mutable.

So if you want to change the objects that you put in the queue
(your example above), you cannot use a tuple.

--Irmen





More information about the Python-list mailing list