osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Can global variable be passed into Python function?


>>> # a swapping variant
>>> def swap(a, b):
...     ab = [a, b]
...     ab[1], ab[0] = ab[0], ab[1]
...     return ab[0], ab[1]
...     
>>> a = 111
>>> id(a)
505627864
>>> b = 999
>>> id(b)
58278640
>>> a, b = swap(a, b)
>>> a, id(a)
(999, 58278640)
>>> b, id(b)
(111, 505627864)

jmf