osdir.com


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

[Tutor] beginning to code


On Fri, 22 Sep 2017 08:48 pm, bartc wrote:

> Can Python be used to write, say, a swap() function that works with any
> argument types (not just classes or lists)? Example:
> 
>      def swap(&a,&b):        # made up syntax
>          a, b = b, a
> 
>      x=10
>      y="Z"
>      swap(x,y)
>      print (x,y)             # "Z" and "10"
> 
> If not, then it doesn't have reference passing as it is normally understood.

No it cannot, and does not. You can emulate it by adding a layer of redirection,
but that's it.



-- 
Steve
?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure
enough, things got worse.