Mar-04-2019, 07:13 AM
(This post was last modified: Mar-04-2019, 07:14 AM by walkinrain.)
The parameters are exchanged within the function and do not affect the value of the variable with the same name outside the function.
example:
example:
a = 100 b = 200 def swap(a, b): x=a a=b b=x # The above code is equivalent to "a, b=b, a" return a,b def swap2(): global a,b a,b=b,a x,y = swap (a, b) print (f"a={a},b={b},x={x},y={y}") swap2() print (a,b)output:
Output:a=100,b=200,x=200,y=100
200 100