Pass variable by reference
Marko Rauhamaa
marko at pacujo.net
Tue May 6 05:11:15 EDT 2014
Steven D'Aprano <steve at pearwood.info>:
> On Mon, 05 May 2014 17:39:44 -0700, Satish Muthali wrote:
>> I have a burning question on how to pass variable by reference in
>> Python. I understand that the data type has to be mutable.
>
> [...]
>
> To get an effect *similar* to pass-by-reference, you can wrap your
> variable in a list, and then only operate on the list item.
Consider also returning multiple values in a tuple.
In C:
stats_read(stats, &characters, &words, &lines);
In Python:
characters, words, lines = stats.read()
Marko
More information about the Python-list
mailing list