The “does Python have variables?” debate
Ethan Furman
ethan at stoneleaf.us
Wed May 7 09:00:35 EDT 2014
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~
More information about the Python-list
mailing list