On Tue, Apr 27, 2010 at 6:09 AM, Anton Shishkov <anton.shish...@gmail.com> wrote: > Hi, I can't figure out how can I change the variable type in function. > In C I could do that easily by changing pointer. > > Code: > def add(b): > > b = {} > print type(b) > > a = [] > print type(a) > add(a) > print type(a) > > Output: > <type 'list'> > <type 'dict'> > <type 'list'>
Python uses call-by-object (http://effbot.org/zone/call-by-object.htm), so what you're trying to do isn't possible. One would normally just return the new object as a result instead. If you have a more concrete example, someone might be able to suggest a better approach. Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list