On 05/06/2014 11:18 PM, Marko Rauhamaa wrote:

Actually, while Python variables are not first-class objects, one could
see them as dictionary-key pairs. So you can even pass them by reference
by passing the dictionary and the key.

Well, you could pass them that way, but not necessarily change them:

--> def func1():
...   a = 1
...   b = 2
...   swap(locals(), 'a', 'b')
...   print a
...   print b
...
--> def swap(d, key1, key2):
...   print d[key1], d[key2]
...   d[key1], d[key2] = d[key2], d[key1]
...   print d[key1], d[key2]
...
--> func1()
1 2
2 1
1
2

--
~Ethan~
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to